I’m using this with success
$str = "{source}do_something";
if(substr($str, 0, 8) == "{source}")
but what should I do if I’ve
$str = "<br><br>{source}do_something";
the goal is to be able of adding blank lines (as many as needed) before firing up my do_something
Thanks
EDIT
ok, so I need to run the function
menu;vertical,true
but I also need to have those blank lines before my menu
my string is
<br><br><br><div>{source}_menu_;vertical,true{/source}</div>
with no line breaks I use
if(substr($pos, 0, 8) == "{source}") {
$campos = substr_replace($description, '', 0, 8);
$campos = substr($campos, 0, -9);
$funcao = explode(";", $campos);
call_user_func_array($funcao[0], array($funcao[1]));
}
now I need the same thing but with the line breaks, so the browser actually renders line breaks and then runs the function.
I hope my english is good enough to make this clear…
Thanks
NEW EDIT with solution
$startTag = "{source}";
$endTag = "{/source}";
$initial_strpos = strpos($str, $startTag);
$final_strpos = strpos($str, $endTag);
if ($initial_strpos !== false) {
$beforeTag = substr($str, 0, $initial_strpos);
echo htmlspecialchars_decode($beforeTag, ENT_QUOTES);
$start = $initial_strpos + strlen($startTag);
$innerText = substr($str, $start, strpos($str, $endTag)-$start);
$funcao = explode(";", $innerText);
call_user_func_array(array_shift($funcao), $funcao);
$aferTag = strpos($str, $final_strpos);
echo htmlspecialchars_decode($aferTag, ENT_QUOTES);
}
this will print my line breaks and run my function.
If you have to check the first 8 characters specifically, then you should remove the
<br>s from the string before doing the substring:This won’t work if the string is slightly different, i.e.
<br />. The best way to do this would probably be:EDIT
How about this? It should get the text between the
{source}{/source}tags and split them by;, then take the first entry as the function name and the second as parameters to the function.