How do I find any string Perl? - string

I am new at Perl and I've got a problem.
I would like to find any string in this part of code:
my $change = $item->look_down(
_tag=> 'td',
class => 'colZmiana change ' #?????
);
In my HTML code, there is colZmiana change up, colZmiana change down or colZmiana change.
I would like class => find every colZmiana change.
Could anyone help me ?

Related

Can´t find the correct class for string methods in Godot

I am trying to make my program read and edit text. I was trying to use the Position=find ( String , 0 ) method but I get the error:
The method "find" isn't declared in the current class.
I have tried different classes but I cant find the correct one.
Which would that be?
How may I find the correct class in the future?
Thanks in advance.
The find is in the String class.
From the documentation:
int find ( String what, int from=0 )
Finds the first occurrence of a substring. Returns the starting position of the substring or -1 if not found.
So what happens?
When you do Position = find(String, 0) You are calling find from which ever class your code is inside, not from String.
Furthermore, I only see one String there… Which String do you want to find in which one? You need two. Yes, find only takes one String, but it is an instance method, not a static method. You are meant to call it on the one you want to search, like this:
var position := string_in_which_you_are_looking.find(string_you_are_looking_for, 0)

Can't seem to nest php variable inside shortcode

I've had a look at various StackOverflow questions but still can't seem to find a successful way to use a variable inside a shortcode. The code in question is as follows (the variable I'm trying to insert into the shortcode is $track_audio.
<?php
$track_audio = get_sub_field('mp3_url');
$renderedShortcode = do_shortcode('[fusion_audio src=". $track_audio . loop="off"][/fusion_audio]');
echo $renderedShortcode; ?>
I've read a fair few conversations on Stackoverflow but have not found a solution that works. The last idea i tried was to concatenate the variable (see code) but that hasn't worked either. Is anyone able to tell me the correct way to do this?
Many thanks in advance for your help with this
Phil
Try this way working for me
Change code from
$renderedShortcode = do_shortcode('[fusion_audio src=". $track_audio . loop="off"][/fusion_audio]');
TO
$renderedShortcode = do_shortcode('[fusion_audio src="'.$track_audio.'" loop="off"][/fusion_audio]');
Final conclision:
$track_audio = get_sub_field('mp3_url');
$renderedShortcode = do_shortcode('[fusion_audio src="'.$track_audio.'" loop="off"][/fusion_audio]');
echo $renderedShortcode;
function fusion_audio_shortcode_func( $atts, $content = null ) {
extract( shortcode_atts(
array(
'loop' => '',
), $atts )
);
$loop;
return '<awesomeness>' . $content . '</awesomeness>';
}
add_shortcode( 'fusion_audio', 'fusion_audio_shortcode_func' );

Finding string in the textfield. Actionscript

What is the best way to find a string (sentence of 1-3 lines) in the multiline textfield.
I have a textfield with a list of messages. In order to change every second messages color, i have to get the index where this message beggins.
ANy ideas?
I solved my problem. Maybe it will be useful for someone.
As i'm appending text, i use textfield.caretIndex to see the inserts. So i'm switching formats using this function:
if (i % 2 != 0) {
textfield.setTextFormat(colorFormat, lastCaret , textfield.caretIndex);
formatStart = textfield.caretIndex;
}
else {
textfield.setTextFormat(textFormat, formatStart, textfield.caretIndex);
lastCaret = textfield.caretIndex;
}

Playn text wrapping and style issue

As in Effect.shadow() is deprecated in PlayN1.3.So i had something like this before :
TextFormat textFormat = new TextFormat(myFont, textWidth, Alignment.LEFT, colorCode, Effect.shadow(-16777216, shadowX, shadowY));
So i changed it to this :
TextFormat textFormat = new TextFormat();
textFormat.withFont(myFont);
textFormat.withWrapping(textWidth, Alignment.LEFT);
I dont want shadow now.It's ok but i did not get previous like result.Hold on.dont think now.Then i changed this code to this:
TextFormat textFormat = new TextFormat().withFont(myFont).withWrapping(textWidth, Alignment.LEFT);
It gives me result as previous except shadow which i dont care now.If i am not wrong this is one line representation of above code.Is not it?
So why it worked and above code did not.Any conceptual difference is there? Anyone can explain please!
//note: dont worry about variables(textWidth,myFont)they are nothing to do with this.
TextFormat objects are immutable. When you call textFormat.withFont(myFont) that returns a new TextFormat instance, which the code above is throwing away. If you want the first code to work you need to write it like this:
TextFormat format = new TextFormat();
format = format.withFont(myFont);
format = format.withWrapping(textWidth, Alignment.LEFT);

preg_replace: reference object in replacement

Do you know of any way to reference an object in the replacement part of preg_replace. I'm trying to replace placeholders (delimited with precentage signs) in a string with the values of attributes of an object. This will be executed in the object itself, so I tried all kinds of ways to refer to $this with the /e modifier. Something like this:
/* for instance, I'm trying to replace
* %firstName% with $this->firstName
* %lastName% with $this->lastName
* etc..
*/
$result = preg_replace( '~(%(.*?)%)~e', "${'this}->{'\\2'}", $template );
I can't get any variation on this theme to work. One of the messages I've been getting is: Can't convert object Model_User to string.
But of course, it's not my intention to convert the object represented by $this to a string... I want to grab the attribute of the object that matches the placeholder (without the percentage signs of course).
I think I'm on the right track with the /e modifier. But not entirely sure about this either. Maybe this can be achieved much more simple?
Any ideas about this? Thank you in advance.
Like I commented to Paul's answer: in the meanwhile I found the solution myself. The solution is much more simple than I thought. I shouldn't have used double quotes.
The solution is as simple as this:
$result = preg_replace( '~(%(.*?)%)~e', '$this->\\2', $template );
Hope this helps anyone else for future reference.
Cheers.
Check out preg_replace_callback - here's how you might use it.
class YourObject
{
...
//add a method like this to your class to act as a callback
//for preg_replace_callback...
function doReplace($matches)
{
return $this->{$matches[2]};
}
}
//here's how you might use it
$result = preg_replace_callback(
'~(%(.*?)%)~e',
array($yourObj, "doReplace"),
$template);
Alternatively, using the /e modifier, you could maybe try this. I think the only way to make it work for your case would be to put your object into global scope
$GLOBALS['yourObj']=$this;
$result = preg_replace( '~(%(.*?)%)~e', "\$GLOBALS['yourObj']->\\2", $template );

Resources