MyBB Community Forums

Full Version: str_replace
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,


I have something like that


$message = str_replace(' twist', ' <a href="http://www.slotstrana.com/?track=NTgyOjE">Twist</a>', $message);

why this code replace twist in this message, i dont wont replace in links and img


[url=http://www.slotstrana.com/?track=NTgyOjE][img]http://i1208.photobucket.com/albums/cc363/FAZIII1/twists_zps93e003ec.png[/img][/url]
You have a space before the 't' so it looks for a space before the t in twist.
but in this code, no spaces
[url=http://www.slotstrana.com/?track=NTgyOjE][img]http://i1208.photobucket.com/albums/cc363/FAZIII1/twists_zps93e003ec.png[/img][/url]
and this twist is stil replaced
com/albums/cc363/FAZIII1/twists_zps93e003ec.
I think you may need to use preg_replace and preg_match in that case.
Maybe this:
if(preg_match("/twist/is", $message) && !preg_match("/\([url=(.*)\](.*)\[\/url\]|\[img\](.*)\[\/img\])/is", $message))
{
$message = preg_replace("/\stwist\s/is", '<a href="http://www.slotstrana.com/?track=NTgyOjE">Twist</a>' ,$message);
}

I'm not making any guarantees though.
so close
wont replace all twist (not in links and img)
Another option you could do is use my Theme Variables Plugin. This is the basic version of the plugin which is free. If you want to know what else the premium version has, message me. While it normally is meant to be used directly in templates, if it is used in a post, it will parse according to the instructions. Note that as of right now, if you use quick reply you have to refresh the page to see what it looks like as parsed. This is an issue a plan on addressing once I finish some other things.

You would just install it, navigate to the Styles & Templates tab. Click Theme Variables, create variable and fill out the form.
(2015-01-29, 05:12 PM)dragonexpert Wrote: [ -> ]Another option you could do is use my Theme Variables Plugin.  This is the basic version of the plugin which is free.  If you want to know what else the premium version has, message me.  While it normally is meant to be used directly in templates, if it is used in a post, it will parse according to the instructions.  Note that as of right now, if you use quick reply you have to refresh the page to see what it looks like as parsed.  This is an issue a plan on addressing once I finish some other things.

You would just install it, navigate to the Styles & Templates tab.  Click Theme Variables, create variable and fill out the form.

i wont use this in message (post)