galvin Posted November 30, 2008 Share Posted November 30, 2008 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); Quote Link to comment https://forums.phpfreaks.com/topic/134892-solved-str_replace-not-doing-what-i-feel-it-should/ Share on other sites More sharing options...
DarkWater Posted November 30, 2008 Share Posted November 30, 2008 Does str_replace NOT work with Select menus or something?.... I hope you realize how ridiculous that sounds, no offense. Anyway, you see what you're echoing the string before you str_replace() it? Hmm... Quote Link to comment https://forums.phpfreaks.com/topic/134892-solved-str_replace-not-doing-what-i-feel-it-should/#findComment-702425 Share on other sites More sharing options...
DeanWhitehouse Posted November 30, 2008 Share Posted November 30, 2008 <?php $string ="<option class='' value='1'>Philadelphia Eagles</option>"; echo str_replace("class=''", "class='not'", $string); ?> Quote Link to comment https://forums.phpfreaks.com/topic/134892-solved-str_replace-not-doing-what-i-feel-it-should/#findComment-702426 Share on other sites More sharing options...
galvin Posted November 30, 2008 Author Share Posted November 30, 2008 Thanks Blade. Sorry DarkWater, I am very new to PHP so I don't know what's a ridiculous statement and whats not. Quote Link to comment https://forums.phpfreaks.com/topic/134892-solved-str_replace-not-doing-what-i-feel-it-should/#findComment-702434 Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2008 Share Posted November 30, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/134892-solved-str_replace-not-doing-what-i-feel-it-should/#findComment-702460 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.