bbcode url reverse help!

Started on the old forum in March 2012 · view the original in the archive · old links redirect here

10 replies · 798 views · started 14 years ago · 1 min read

4 participants
asifnayem Developer · 119 posts #1

hi in bbcode i did use this to using url

$text = preg_replace("/\[url\=(.*?)\](.*?)\[\/url\]/is","<a href=\"$1\">$2</a>",$text);

but how to reverse it. i mean while editing, how to reverse it like [ url = siteurl] siteurl [ /url]

something else Fellow · 2,296 posts #2
$text = preg_replace("/<a href=\"(.*?)\">(.*?)<\/a>/is","[url=$1]$2[/url]",$text);

but far better off not saving it in database as html

asifnayem Developer · 119 posts #3

something else wrote: but far better off not saving it in database as html

any problem/exploit can be happen if i use saving as html in database? i use htmlspecialchars() while input in database and htmlspecialchars_decode() to show in front end. please reply

something else Fellow · 2,296 posts #4

na should be fine .... it just means your having to store more than you need in your database 🙂

asifnayem Developer · 119 posts #5

then what should i do to leverage this? btw, i also can't reverse the img bbcode

[img][/img]

please reverse this.

bestman Junior · 32 posts #6

pls does any one have johncms 4.4.0 bbcode for titled link, i.e if i post a link 9jamobile.net - File host it wil replace it to the site title

Added after 8 minutes:

just like what has happend above

something else Fellow · 2,296 posts #7

asifnayem wrote: then what should i do to leverage this? btw, i also can't reverse the img bbcode


please reverse this.

$text = preg_replace("/<img src=\"(.*?)\" alt=\"(.*?)\"\/>/is","[img]$1[/img]",$text);

You may have to alter it slightly depending on number of space in your <img> tag

Added after 11 minutes:

bestman wrote: pls does any one have johncms 4.4.0 bbcode for titled link, i.e if i post a link 9jamobile.net - File host it wil replace it to the site title

Added after 8 minutes:

just like what has happend above

heres with DOM :

function gettitle($url)
{
        $dom = new DOMDocument();
        if($dom->loadHTMLFile($url))
        {

            $list = $dom->getElementsByTagName("title");
            if ($list->length > 0)
            {
                return $list->item(0)->textContent;
            }
        }
}

$in=array('`((?:https?|ftp)://\S+[[:alnum:]]/?)`si','`((?<!//)(www\.\S+[[:alnum:]]/?))`si');
$out=array('<a href="$1">'.gettitle($1).'</a>','<a href="http://$1">'.gettitle('http://'.$1).'</a>');
$text = preg_replace($in,$out,$text);

//ugh some bug with opera doesnt let you see end of php file on this forum so i put this comment in there just so i can see the bottom line

otherwise you would have to use curl or get_file_contents()

something else Fellow · 2,296 posts #8

something else wrote: heres with DOM :

function gettitle($url)
{
        $dom = new DOMDocument();
        if($dom->loadHTMLFile($url))
        {

            $list = $dom->getElementsByTagName("title");
            if ($list->length > 0)
            {
                return $list->item(0)->textContent;
            }
        }
}


$in=array('`((?:https?|ftp)://\S+[[:alnum:]]/?)`si','`((?<!//)(www\.\S+[[:alnum:]]/?))`si');
$out=array('<a href="$1">'.gettitle($1).'</a>','<a href="http://$1">'.gettitle('http://'.$1).'</a>');
$text = preg_replace($in,$out,$text);

//ugh some bug with opera doesnt let you see end of php file on this forum so i put this comment in there just so i can see the bottom line

otherwise you would have to use curl or get_file_contents()

oops wont work with array but you can use the dom function to add to a different auto url bb 🙂

asifnayem Developer · 119 posts #10

something else wrote: You may have to alter it slightly depending on number of space in your <img> tag

i am using this

	$text = preg_replace("/\[img\](.*?)\[\/img\]/", "<img src=\"http://localhost/blog/thumb.php?image=$1&w=150&h=150\" alt='*' class='imf'/>", $text);

its not working then i use

$text = preg_replace("/<img src=\"(.*?)\" alt=\"(.*?)\" class=\"imf\"\/>/is","[img]$1[/img]",$text);

it shows the whole http://localhost/blog/............

nidayaqoob1230 Newbie · 1 posts #11

Hi i found this html code for the live traffic feed. i want this converted to BBcode so that i can put ot on a site that supports only BBcode,. say a site like songs - Listen to free music.. I need help. Can someone help me out with converting this html to BBcode. i tried a few online converters.. but none of them work..

this is the code..

<script type="text/javascript" src="http://feedjit.com/serve/?vv=693&tf… href="http://feedjit.com/">Feedjit Live Blog Stats</a></noscript>

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close