The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Trying to do replacements
I'm trying to use the preg_replace command to do replacements of specific strings with the string as a URL. An example from what I am using:
PHP Code:
I have two issues: 1. I cannot quite figure out how to get ONLY exact matches, no matter where they might appear in the post. I've been reading on this here: http://www.php.net/manual/en/function.preg-replace.php and here: http://www.php.net/manual/en/pcre.pattern.modifiers.php 2. I know that I will need a if/then loop to prevent the substitution from being made if the string is already encased in <a> or [URL] tags, but I am not sure how to go about that either. I am currently using this in the functions_showthread.php file for vB 3.0.0 RC3, so no actual changes are being made to the data as the subs are done on the display end of things. Thanks in advance! |
#2
|
|||
|
|||
dontpanic,
Could you perhaps use either str_replace or substr_replace functions instead to get the effect you're looking for? I haven't really done much with preg_replace so I can't really give you much assistance there. Cheers, g-force2k2 |
#3
|
|||
|
|||
g-force2k2,
This code below does have the same effect, but my real problem is figuring out how to prevent it from replacing in any <a> or [URL] instances. PHP Code:
You've got me looking in another direction though... |
#4
|
||||
|
||||
Note that str_replace() is case sensitive, so for the words for example it will only match exact case and you can't tell it to replace abc and not <a href="x">abc</a>
|
#5
|
|||
|
|||
NTLDR,
Good point. I am having the same problems with str_replace() as I did with preg_replace() when we talked last. I have to figure out a way to prevent the replacement from occuring in existing <a> and [URL] instances as the replacement will break them and some times create interesting output as well. Thanks both for your inputs. |
#6
|
|||
|
|||
dontpanic couldn't you nest your replacement codes in characters that are illegal in urls, characters that the urlencode function changes.
for example: Code:
{70-292} That way you don't have to worry about parsing through the urls or a hrefs. Also take a look at the functions_bbcodeparse.php might give you some ideas. Regards, g-force2k2 |
#7
|
||||
|
||||
Quote:
PHP Code:
|
#8
|
|||
|
|||
Quote:
|
#9
|
|||
|
|||
Quote:
|
#10
|
|||
|
|||
Quote:
Regards, g-force2k2 |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|