mms_master
asked on
BB Code Replacement Help
Hi,
I am making a forum and want to include BB Code in it.
So far it replaces BB Code like [b]text[/b] and [url]http://www.google.com[/url]
But I want it to replace BB Code like [url=http://www.google.com]Google[/url]
The code I have so far is:
====================PHP=== ========== =====
if ($Bb_Code_Row['Advanced_Re place'] > "") {
$Post_Main_Text = str_replace($Bb_Code_Row[' Open_Code' ] . ".]", $Bb_Code_Row['Open_Replace '] . "$1" . $Bb_Code_Row['Advanced_Rep lace'], $Post_Main_Text);
$Post_Main_Text = str_replace($Bb_Code_Row[' Close_Code '], $Bb_Code_Row['Close_Replac e'], $Post_Main_Text);
} else {
$Post_Main_Text = str_replace($Bb_Code_Row[' Open_Code' ], $Bb_Code_Row['Open_Replace '], $Post_Main_Text);
$Post_Main_Text = str_replace($Bb_Code_Row[' Close_Code '], $Bb_Code_Row['Close_Replac e'], $Post_Main_Text);
}
===================PHP==== ========== =====
The html output for the advanced BB Code (being [url= ] [/url]) is (using Google as an example):
<a href='http://www.google.com]Google</a>
If I replace ] with '> it will replace it for all other BB Codes (e.g. [b]text[/b] would become <b'>text</b'>) which obviously would cause problems.
I've thought about doing it with a pattern, but can't work out how.
Can anyone help me please?
Thanks In Advance
mms_master
I am making a forum and want to include BB Code in it.
So far it replaces BB Code like [b]text[/b] and [url]http://www.google.com[/url]
But I want it to replace BB Code like [url=http://www.google.com]Google[/url]
The code I have so far is:
====================PHP===
if ($Bb_Code_Row['Advanced_Re
$Post_Main_Text = str_replace($Bb_Code_Row['
$Post_Main_Text = str_replace($Bb_Code_Row['
} else {
$Post_Main_Text = str_replace($Bb_Code_Row['
$Post_Main_Text = str_replace($Bb_Code_Row['
}
===================PHP====
The html output for the advanced BB Code (being [url= ] [/url]) is (using Google as an example):
<a href='http://www.google.com]Google</a>
If I replace ] with '> it will replace it for all other BB Codes (e.g. [b]text[/b] would become <b'>text</b'>) which obviously would cause problems.
I've thought about doing it with a pattern, but can't work out how.
Can anyone help me please?
Thanks In Advance
mms_master
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
If it isn't possible to keep it in $Post_Main_Text can you tell me how to replace it and then sepereate the string and post the replacementin the right place.
Or if there is another way to do it then could you tell me please?
The strings will be coming from a database and the code I need will be in a while loop.
Or if there is another way to do it then could you tell me please?
The strings will be coming from a database and the code I need will be in a while loop.
ASKER
I searched on google, found some code and modified it.
It's similar to what you said but using pred_replace() instead of preg_match().
Thanks anyway for the help and scene as you gave me an idea of what I was looking for i'll give you the points.
mms_master
It's similar to what you said but using pred_replace() instead of preg_match().
Thanks anyway for the help and scene as you gave me an idea of what I was looking for i'll give you the points.
mms_master
ASKER
I need my code to keep the url in $Post_Main_Text, because otherwise I have to seperate it out to put $href back in the right part of the post.