The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
How to exclude url tage
Hello,
I use plugin. But i need to exclude url's "Anchor Text" inside post's to NOT effected. Any help please? Thank you |
#2
|
|||
|
|||
What hook is your replacement plugin using, is it before or after bbcode replacement?
|
#3
|
|||
|
|||
postbit_display_complete
Thanks for help |
#4
|
|||
|
|||
OK, there may be some more elegant way someone knows to do it (in which case, please post it), but here's what I came up with:
Code:
$word = array( 'google', 'yahoo' ); $link = array( '<a href="http://google.com">google</a>', '<a href="http://yahoo.com">yahoo</a>' ); $parts = preg_split('#(<a|</a)#i', $this->post['message'], -1, PREG_SPLIT_DELIM_CAPTURE); $newmsg = ''; $inlink = false; foreach ($parts as $part) { if (strcasecmp($part, "<a") == 0) $inlink = true; else if (strcasecmp($part, "</a") == 0) $inlink = false; else if (!$inlink) $part = str_replace($word, $link, $part); $newmsg .= $part; } $this->post['message'] = $newmsg; |
#5
|
|||
|
|||
You are wonderful kh99,
Its work like a CHARM Without any error, YOU ARE GREAT believe me. If you have a website just pm me the link with title, i will add link on my home page PR4 for your website. Grateful for you and Thanks a lot Quote:
I am sorry, There is problem on images TAG I need to exclude images IMG tags inside post's to NOT effected. I am sorry kh99, please help me to fix it. Thank you |
#6
|
|||
|
|||
Yeah, I had a feeling you'd evenutally find a problem with that. It's hard to get stuff like that to be bulletproof (or at least it's hard for me).
Anyway, try this: Code:
$word = array( 'google', 'yahoo' ); $link = array( '<a href="http://google.com">google</a>', '<a href="http://yahoo.com">yahoo</a>' ); // Match any HTML tag, this will be the delimiter in preg_split $regexp = "/(<\/?\w+((\s+(\w|\w[\w-]*\w)(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)\/?>)/i"; // Capture delimiters and offsets. This will also capture things multiple times because of the // multiple parens used in the pattern, so we'll have to skip them in the loop below $parts = preg_split($regexp, $this->post['message'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE); $newmsg = ''; $intag = false; $offset = 0; foreach ($parts as $part) // $part is array, 0 = string 1 = offset (because of PREG_SPLIT_OFFSET_CAPTURE) { if ($part[1] < $offset) // ignore parts from other parens in regexp continue; $offset = $part[1] + strlen($part[0]); if (strncasecmp($part[0], '<a', 2) == 0 || strncasecmp($part[0], '<img', 4) == 0) { if (strcasecmp(substr($part[0], -2), '/>') == 0) // check for self-closed tag $intag = false; else $intag = true; } else if (strncasecmp($part[0], '</a', 3) == 0 || strncasecmp($part[0], '</img', 5) == 0) $intag = false; else if (!$intag) $part[0] = str_replace($word, $link, $part[0]); $newmsg .= $part[0]; } $this->post['message'] = $newmsg; It's getting ugly now... |
#7
|
|||
|
|||
Thats IT,
Great, I really very appreciate your patience and help, Thank you so much kh99. |
#8
|
||||
|
||||
I would have searched for " google" or "google " (note the space) and replaced them with " <a href="http://google.com">google</a> " and the same for yahoo. Requiring the space as part of the string would mean www.google.com or http://google.com wouldn't be effected. The extra space introduced by the replacement is usually ignored anyway.
|
#9
|
|||
|
|||
That's a good idea, that might have solved the OP's problem. I guess since it says "Anchor Text" in the first post I was thinking the problem was the text and not the url. But it might have been a translation thing because it makes more sense that the url would be the problem.
|
#10
|
||||
|
||||
He seems to have edited the first post, I thought this was more in line with what he originally said but now I'm not so sure.
|
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|