PDA

View Full Version : How do I get a plugin to work that contains quotes in the replace string?


4x4 Mecca
06-10-2008, 04:55 AM
For example, say I have this:

$stuff="<a href="showthread.php">test</a>";
$lookfor='$thread[highlight]';
$replace='$stuff';
$vbulletin->templatecache['threadbit'] = str_replace($lookfor, $replace, $vbulletin->templatecache['threadbit']);
I will get tons of error codes because the $stuff line has quotes in it. I want to do template replacements via plugins rather than changing each file, but this is killing me. Any pointers? Thanks.

MoT3rror
06-10-2008, 06:14 AM
$stuff = '<a href="showthread.php">test</a>';
Just you won't be able to put variables in between or you can do this.
$stuff = "<a href=\"showthread.php\">test</a>";
Which will allow variables in the quotes.

4x4 Mecca
06-10-2008, 03:58 PM
you rock, I'll go try that now.

--------------- Added 1213117994 at 1213117994 ---------------

This is my actual code, it still doesn't load.
$threadprefixstuff="<a href=\"showthread.php?$session[sessionurl]t=$thread[threadid]$thread[highlight]\" id=\"thread_title_$thread[realthreadid]\"<if condition=\"$show[gotonewpost]\"> style=\"font-weight:bold\"</if>>$thread[threadtitle]</a>
$thread[movedprefix]
$thread[typeprefix]
$thread[moderatedprefix]
$thread[prefix_rich]";
$threadprefixlookfor="
$thread[movedprefix]
$thread[typeprefix]
$thread[moderatedprefix]
$thread[prefix_rich]
<a href=\"showthread.php?$session[sessionurl]t=$thread[threadid]$thread[highlight]\" id=\"thread_title_$thread[realthreadid]\"<if condition=\"$show[gotonewpost]\"> style=\"font-weight:bold\"</if>>$thread[threadtitle]</a>";
$threadprefixreplace="$threadprefixstuff";
$vbulletin->templatecache[threadbit] = str_replace($threadprefixlookfor, $threadprefixreplace, $vbulletin->templatecache[threadbit]);

Opserty
06-10-2008, 04:18 PM
You need to use single quotes (instead of double quotes), to encapsulate your search and replace strings e.t.c. As single quotes do not parse variables.

Dismounted
06-11-2008, 06:52 AM
You can use single quotes - you just need to concatenate.