Only letters numbers and one special character at the end?

This is the first time I’ve seen 2 returns.

Is this something new?

AFAIK
http://php.net/manual/en/function.return.php

If called from within a function, the return statement immediately ends execution of the current function

I am not sure I am just doing it in the dark :wink:

Maybe you know how to make this to ignore the special char at the end?

"/#([A-Za-z0-9_]+)(?=\s|\Z)/"

Maybe some like this:

is this returns false:

preg_replace("/#([A-Za-z0-9_]+)(?=\s|\Z)/", '<a href="'.$mybb->settings['bburl'].'/hashtag/\1">#\1</a>', $tweet);

Then trim last character which has to be special since it returns false otherwise it will return true!

It looks like i only need to disallow ; and " and that comes from the HTML code!

K, give me a sec to try a few ideas

Yeah, I still don’t have a good solution for that without stripping out all of that HTML.

Here is what I’d personally do, strip out the HTML, but keep it in another variable, get the list of hashtags in the message and then replace them with links in the HTML variable

function tag_parse($message) {

global $post, $mybb;
$tweet = strip_tags($message); // $message still has the HTML
preg_match_all("/#([A-Za-z0-9_]+)/", $tweet, $tags); // get a list of tags

//loop through the tags and replace their match in the HTML message
foreach ($tags as $tag)
{
  $message = str_replace('#'.$tag, '<a href="' . $mybb->settings['bburl'].'/hashtag/'.$tag.'">#'.$tag.'</a>', $message);
}
return $message; 

}

I have not tested this code, so no idea if it works.

buddy OMG thanks so much please need a bit more help.

How can I:

Match and remove bbcode and it’s content.

And how can I find and remove this:

color:#somecolor;

I mean wanna pattern to find and remove css code to prevent it being grabbed as tag?

So rather than continuing to just hand you the answer to your homework…

Here’s a question to answer your question.

What defines a ‘bbcode’? What defines the content of bbcode?

Buddy sorry I ma learning please be merciful.

I am using this: #\[[^]]*\]# but it doesn’t remove content inside the bbcode!

how are you using it? That pattern looks correct… (probably could do with a \ in front of the ] inside the class, but it… should work without it.

And… do you mean you want to remove EVERYTHING inside a pair of BBcode tags?

My message looks like this:

style="color: #333333;"

[code]
alt="hello"
[/code]
[php]
alt="hello"
[/php]

[quote='q21051983' pid='17278' dateline='1439393638'] [color=#FF0000]hello[/color] this is a test #SEO[/quote]

#seoooo. [color=#FF0000]test[/color] #seii, hello

And it returns this:

style="color: #333333;"


alt="hello"


alt="hello"


 hello this is a test #SEO

#seoooo. test #seii, hello

I am using this:

$a = strip_tags($post['message']);



     $pattern = '#\[[^]]*\]#';
    $replace = '';
    $b = preg_replace($pattern, $replace, $a);
    
    echo $b;

I would like to remove everything inside the bbcode tags and find and remove color:#somecolor;

So… this pattern’s gonna get a bit unique.

<?php
$pattern = "#\[(?<start>[^\s\]=]*)[^\]]*].*?\[\/\k<start>\]#"

Find the color:#somecolor as a separate thing.

Buddy thanks so much for your time really appreciate.

It returns this:

style=“color: #333333;”

[code]
alt="hello"
[/code]
[php]
alt="hello"
[/php]

#seoooo.  #seii, hello

Didn’t affect code and php nor color? People some time add spaces like this: color: #fff;

This looks like took care of the color:

 **$pattern = '/color:(.*?);.*/';**

Sorry, forgot the pattern modifier.

"#\[(?<start>[^\s\]=]*)[^\]]*].*?\[\/\k<start>\]#s"
1 Like

F* me side ways! Buddy you just saved the day man stayed whole night with this.

WORKS dude I love you :wink:

SOLVED bye

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.