the-botman Posted November 16, 2009 Share Posted November 16, 2009 ok hi guys ... i am not sure if i am posting my question in the rite place but here goes. i want to str_replace all numbers between 0-60 and change the colour of the numbers this is what i have and it works but using this way i need to have 60 lines of code is a any other way? $Fguide = str_replace('0','<font face="Verdana" color="red" size="2">0</font>',$Fguide); Quote Link to comment https://forums.phpfreaks.com/topic/181783-solved-str_replace/ Share on other sites More sharing options...
premiso Posted November 16, 2009 Share Posted November 16, 2009 $i=0; $upper = 60; while ($i <= $upper) { $Fguide = str_replace($i, '<font face="Verdana" color="red" size="2">' . $i . '</font>', $Fguide); $i++; } A simple while loop does wonders for ya Quote Link to comment https://forums.phpfreaks.com/topic/181783-solved-str_replace/#findComment-958710 Share on other sites More sharing options...
the-botman Posted November 16, 2009 Author Share Posted November 16, 2009 not working Quote Link to comment https://forums.phpfreaks.com/topic/181783-solved-str_replace/#findComment-958713 Share on other sites More sharing options...
premiso Posted November 16, 2009 Share Posted November 16, 2009 not working Hmm that gives me a TON of information to help you out....if it is not working either: A. You omitted a good chunk of code, post that here so it can be tailored a bit more. B. See A. Quote Link to comment https://forums.phpfreaks.com/topic/181783-solved-str_replace/#findComment-958714 Share on other sites More sharing options...
MadTechie Posted November 16, 2009 Share Posted November 16, 2009 C. try re-installing the internet (just an idea) also a joke! Quote Link to comment https://forums.phpfreaks.com/topic/181783-solved-str_replace/#findComment-958720 Share on other sites More sharing options...
the-botman Posted November 16, 2009 Author Share Posted November 16, 2009 i am sorry i am very new to php , ok see i am pulling the tv guide from a site to mine it displays like this http://bhawap.com/TvGuide-sabc1.php and your code works but only if u change it to $i=2; $upper = 60; while ($i <= $upper) { $FGuide = str_replace($i, '<font face="Verdana" color="red" size="2">' . $i . '</font>', $FGuide); $i++; } will look like http://bhawap.com/TvGuide-etv.php but if i add it the way u show me will display like http://bhawap.com/TvGuide-sabc2.php Quote Link to comment https://forums.phpfreaks.com/topic/181783-solved-str_replace/#findComment-958727 Share on other sites More sharing options...
the-botman Posted November 16, 2009 Author Share Posted November 16, 2009 if u want i can paste my whole code i just did not want to flood this section and i am sorry for any mistake in my questions Quote Link to comment https://forums.phpfreaks.com/topic/181783-solved-str_replace/#findComment-958729 Share on other sites More sharing options...
MadTechie Posted November 16, 2009 Share Posted November 16, 2009 You are placing EVERY number from 0 to 60.. so the results your getting are correct.. also $i should be 0 I think you want to limit your replacement, ie every quoted number ie "0" That's just an example Quote Link to comment https://forums.phpfreaks.com/topic/181783-solved-str_replace/#findComment-958732 Share on other sites More sharing options...
premiso Posted November 16, 2009 Share Posted November 16, 2009 You want the reason, because after you iterate it up passed 0 and 1 it replaces 2 which there are "2"'s that are inside the tags, the flaw is that there are tags in the code and of course if a tag is created within a tag it will cause issues: <font face="Verdana" color="red" size="<font face="Verdana" color="red" size="2">2</font>">0</font> Notice how it is replacing the 2 inside the <font> tag, which of course will cause display issues. The code I provided works, it is just that since the code replaced has a 2 in it, causes a little issue that anything replaced before that will be replaced. A better method of doing this, use a CSS style so you do not get this error. <style type="text/css"> .redColor { color: red; font-size: 15px; font-family: Verdana; } </style> <?php $i=0; $upper = 60; while ($i <= $upper) { $FGuide = str_replace($i, '<font style="redColor">' . $i . '</font>', $FGuide); $i++; } ?> Will solve that problem. EDIT: I should have caught that ahead of time, sorry for that. Quote Link to comment https://forums.phpfreaks.com/topic/181783-solved-str_replace/#findComment-958734 Share on other sites More sharing options...
the-botman Posted November 16, 2009 Author Share Posted November 16, 2009 ok thanks alot for all your help and sorry again i also found a way to make it work hehe but yours is the best as always hehe here was my way $i=2; $upper = 60; while ($i <= $upper) { $FGuide = str_replace($i, '<font face="Verdana" color="red" size="2">' . $i . '</font>', $FGuide); $i++; } $FGuide = str_replace('0', '<font face="Verdana" color="red" size="2">0</font>', $FGuide); $FGuide = str_replace(1, '<font face="Verdana" color="red" size="2">1</font>', $FGuide); return $FGuide; thanks again i will close this topic if u dont reply in 20 min hehe cheers Quote Link to comment https://forums.phpfreaks.com/topic/181783-solved-str_replace/#findComment-958740 Share on other sites More sharing options...
MadTechie Posted November 16, 2009 Share Posted November 16, 2009 I foresee problems! Quote Link to comment https://forums.phpfreaks.com/topic/181783-solved-str_replace/#findComment-958745 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.