Something wrong with my str_replace()?

Take a look at this:

$row_getCalEve = str_replace(‘SEE GOOGLE CALENDAR AT BOTTOM OF PAGE’, ‘<a href=“#calendar”>SEE GOOGLE CALENDAR AT BOTTOM OF PAGE</a>’, $row_getCalEve);

Does anyone see anything wrong with this? I’m trying to get ‘SEE GOOGLE CALENDAR AT BOTTOM OF PAGE’ to turn into a link within a page and it doesn’t seem to be working.

No error messages. Just no link being created.

What is the initial value of $row_getCalEve
If the first term is not found within the third term, no change will occur.

str_replace searches the third term (the haystack) for the first term (the needle) and replaces it with the second term.

Thanks, pmw57. I guess I need to look into this a little further. I’ve never really had a problem using this str_replace, but it doesn’t seem to be working as I thought it would.

The initial value is FIRE ACADEMY CALENDAR (SEE GOOGLE CALENDAR AT BOTTOM OF PAGE). I thought by putting in a shortened first value, it would be able to search it simply and replace it with the second value.

I’m using this and it seems to work just fine:
$row_getCalEve = str_replace(‘Calendar’, ‘<a href=“http://this_website”>Calendar</a>’, $row_getCalEve);

I don’t really understand what the difference is.

Would you find it even stranger if I say that it works for me.


<?php
$row_getCalEve = 'FIRE ACADEMY CALENDAR (SEE GOOGLE CALENDAR AT BOTTOM OF PAGE).';
$row_getCalEve = str_replace('SEE GOOGLE CALENDAR AT BOTTOM OF PAGE', '<a href="#calendar">SEE GOOGLE CALENDAR AT BOTTOM OF PAGE</a>', $row_getCalEve);
echo $row_getCalEve;
?>

Output:

FIRE ACADEMY CALENDAR ([SEE GOOGLE CALENDAR AT BOTTOM OF PAGE](#calendar)).

This implies that there is something unaccounted for with your initial $row_getCalEve value.

Actually, yes.

I’ve tried your instance with modification:
$row_getCalEve =‘GOOGLE CALENDAR’;
$row_getCalEve = str_replace(‘GOOGLE CALENDAR’, ‘<a href=“#calendar”>GOOGLE CALENDAR</a>’, $row_getCalEve);

and what I got was this:
<: <

<

Time: <

Download: <

This is the first record displaying. The other eight display fine–the eighth being the text that includes the ‘Google Calendar’ content, but even that isn’t turned into a link.

It seems then that the problem you’re experiencing may be elsewhere.

You can use var_dump($row_getCalEve) after the string replace command to confirm that the string is at that stage, as it should be.

From there you can then trace things further throughout your code in order to figure out where the cause of the problem lies.

Result:
string(39) “GOOGLE CALENDAR”

That’s right, those 39 characters include the <a href part of the code too.