Jump to content

Recommended Posts

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

 

:)

Link to comment
https://forums.phpfreaks.com/topic/115778-solved-echo-issue/
Share on other sites

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;

Link to comment
https://forums.phpfreaks.com/topic/115778-solved-echo-issue/#findComment-595272
Share on other sites

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

 

;)

Link to comment
https://forums.phpfreaks.com/topic/115778-solved-echo-issue/#findComment-595291
Share on other sites

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;

Link to comment
https://forums.phpfreaks.com/topic/115778-solved-echo-issue/#findComment-595457
Share on other sites

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.