Jump to content

[SOLVED] str_replace not doing what I feel it should


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.