str_replace
#1
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]
My Plugins

PM only paid support
Reply
#2
You have a space before the 't' so it looks for a space before the t in twist.
Reply
#3
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.
My Plugins

PM only paid support
Reply
#4
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.
Reply
#5
so close
wont replace all twist (not in links and img)
My Plugins

PM only paid support
Reply
#6
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.
Reply
#7
(01-29-2015, 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)
My Plugins

PM only paid support
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)