Jump to content

[SOLVED] str_replace not doing what I feel it should


galvin

Recommended Posts

I have the following code and I'm trying to replace "class=''" with "class='not'" and the code below, which I feel like should work is not.  Anyone have any idea why it's not replacing?  Does str_replace NOT work with Select menus or something?....

 

$string ="<option class='' value='1'>Philadelphia Eagles</option>";
echo $string;
$cancelteams = str_replace("class=''", "class='not'", $string);

To a programming language, $string and $cancelteams are just variables that contain some data. Php does not know or care what that data is (in fact programming is easy, it is just creating, manipulating, and moving data around.) The contents of the variable only becomes a select menu when it has been output to a browser.

 

The code:

$cancelteams = str_replace("class=''", "class='not'", $string);

Just takes what is in $string and replaces what you told it to and assigns the results to $cancelteams.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.