-entropyman Posted July 21, 2008 Share Posted July 21, 2008 Hello all, Hopefully you can help me, it should be a pretty easy question. I need some help with echo (). more specifically, i need help getting something like this to print: echo "Name is: [color=blue]$name[/color]"; As you can see I want the output so that it is ready to go to a forum. I know I need to add something to the variable I just don't know what lol Any help would be greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/115778-solved-echo-issue/ Share on other sites More sharing options...
Lodius2000 Posted July 21, 2008 Share Posted July 21, 2008 I would put the string to a str_replace() where you have massive arrays of what to be changed and what to change it to Quote Link to comment https://forums.phpfreaks.com/topic/115778-solved-echo-issue/#findComment-595203 Share on other sites More sharing options...
JasonLewis Posted July 21, 2008 Share Posted July 21, 2008 You'd be wanting to learn up on regular expressions and BB code. $name = "Poohead_5152"; $str = "Name is: [color=blue]{$name}[/color]"; $str = preg_replace("/\[color=(.*?)\](.*?)\[\/color\]/","<font color='\\1'>\\2</font>", $str); echo $str; Quote Link to comment https://forums.phpfreaks.com/topic/115778-solved-echo-issue/#findComment-595272 Share on other sites More sharing options...
samshel Posted July 21, 2008 Share Posted July 21, 2008 please post some more code... $name is something that you have to pass to the forum. Quote Link to comment https://forums.phpfreaks.com/topic/115778-solved-echo-issue/#findComment-595274 Share on other sites More sharing options...
-entropyman Posted July 21, 2008 Author Share Posted July 21, 2008 hmmm let me clarify, apologies if i misled you. I would like to have echo actually echo out the words (no actual colors): Name is: [c olor=blue]Bill[/ color] (without spaces in colors) this way one can copy and paste that and it should work in the forum. my issue is I do not know how to tell php to echo that out. this: echo "Name is: [color=blue]$name[/color]"; will just produce a blank page. I believe I need to do something to my variable, for example place a dot in front of it or something hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/115778-solved-echo-issue/#findComment-595291 Share on other sites More sharing options...
samshel Posted July 21, 2008 Share Posted July 21, 2008 $name must be empty. Quote Link to comment https://forums.phpfreaks.com/topic/115778-solved-echo-issue/#findComment-595317 Share on other sites More sharing options...
-entropyman Posted July 21, 2008 Author Share Posted July 21, 2008 not too sure if i understood correctly mate but: $name is set and works fine, just checked it and echoed it but still nothing, just a blank page when I use the echo "Name is: [color=blue]$name[/color]"; Quote Link to comment https://forums.phpfreaks.com/topic/115778-solved-echo-issue/#findComment-595328 Share on other sites More sharing options...
samshel Posted July 21, 2008 Share Posted July 21, 2008 we need more code to figure the problem...possible to post? Quote Link to comment https://forums.phpfreaks.com/topic/115778-solved-echo-issue/#findComment-595331 Share on other sites More sharing options...
JasonLewis Posted July 21, 2008 Share Posted July 21, 2008 Try it like this: echo "Name is: [color=blue]{$name}[/color]"; Quote Link to comment https://forums.phpfreaks.com/topic/115778-solved-echo-issue/#findComment-595451 Share on other sites More sharing options...
Darklink Posted July 21, 2008 Share Posted July 21, 2008 ProjectFear's code should work fine. There's no need for any more code samshel. Quote Link to comment https://forums.phpfreaks.com/topic/115778-solved-echo-issue/#findComment-595454 Share on other sites More sharing options...
JasonLewis Posted July 21, 2008 Share Posted July 21, 2008 Indeed it shall, and if you missed my post further above OP, I've quoted it for your benifit. You'd be wanting to learn up on regular expressions and BB code. $name = "Poohead_5152"; $str = "Name is: [color=blue]{$name}[/color]"; $str = preg_replace("/\[color=(.*?)\](.*?)\[\/color\]/","<font color='\\1'>\\2</font>", $str); echo $str; Quote Link to comment https://forums.phpfreaks.com/topic/115778-solved-echo-issue/#findComment-595457 Share on other sites More sharing options...
-entropyman Posted July 21, 2008 Author Share Posted July 21, 2008 Try it like this: echo "Name is: [color=blue]{$name}[/color]"; that worked, thank you! Quote Link to comment https://forums.phpfreaks.com/topic/115778-solved-echo-issue/#findComment-596014 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.