this is something that should be so simple, but Ive run this code in excess of 90 times trying to figure it out. Any help would be greatly appreciated!
Here is my entire function for context. I am trying to replace
<a href="04.htm">
with
<a style="cursor:pointer;" onclick="gotoScrollExercise(04); return false;">
the function:
$replacethis = '(<a href=\"([0-9]{2})\\.htm\">)';
$linkArr = [];
$lessonNo = preg_match_all($replacethis, $originalcontent, $linkArr);
for($x = 0; $x < count($linkArr[1]); $x++) {
$replacethis = '<a href="'.$linkArr[1][$x].'.htm">';
$replacewith = '<a style="cursor:pointer;" onclick="gotoScrollExercise('. $linkArr[1][$x] .'); return false;">';
$originalcontent = str_replace($replacethis, $replacewith, $originalcontent);
}
If I change the $replacewith variable to something simple, I have no problems but as soon as I add an onclick function, it just ignores that part of the string.
example that works:
$replacewith = '<a id="blah" style="cursor:pointer;">';
Examples that dont work:
$replacewith = '<a fdgdfgdf>';
$replacewith = '<a onclick="function()">';
why?
reproduceable example:
$replacethis = '<a href="04.htm">';
$replacewith = '<a style="cursor:pointer;" onclick="gotoScrollExercise(04); return false;">';
$originalcontent = str_replace($replacethis, $replacewith, $originalcontent);
output is:
<a style="cursor:pointer;">