| View previous topic :: View next topic |
| Author |
Message |
LolSalad Grandmaster Cheater
Reputation: 1
Joined: 26 Aug 2007 Posts: 988 Location: Australia
|
|
| Back to top |
|
 |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Wed Dec 31, 2008 4:37 am Post subject: |
|
|
| but where the hell would i put it? in the <a href=> bit?
|
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Wed Dec 31, 2008 7:03 am Post subject: |
|
|
Not.
Because a link is build like that
<a href="http://fuckthewhat.com">ClickMeh</a>
and not like that <link>lolwut</link>
That means str_replace wont work in that way you are doing it.
| Code: | <?php
$string = "[url]http://www.google.com[/url]";
$stripped = str_replace('[url]', '', $string);
$stripped = str_replace('[/url]', '', $stripped);
$shiet = str_replace('[url]', '<a href="', $string);
$shiet = str_replace('[/url]', '">'.$stripped.'</a>', $shiet);
echo $shiet;
?> |
Kinda complicated.
Yet I suggest you to use regex.
|
|
| Back to top |
|
 |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Wed Dec 31, 2008 7:27 am Post subject: |
|
|
| uh, yea, that code doesn't work.
|
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Wed Dec 31, 2008 7:39 am Post subject: |
|
|
Well sience you don't get all this at all, I decided to write the whole function for you.
Here:
| Code: | function topic($input){
$pregs = array(
'/\[b\](.+)\[\/b\]/' => '<b>$1</b>',
'/\[i\](.+)\[\/i\]/' => '<em>$1</em>',
'/\[u\](.+)\[\/u\]/' => '<u>$1</u>',
'/\[code\](.+)\[\/code\]/' => '<font style="padding:3px;" color="#CC0000" size="2">Code:</font><br><div id="code"><tt>$1</tt></div>',
'/\[url\](.+)\[\/url\]/' => '<a href="$1">$1</em>',
);
$parsedtext = preg_replace(array_keys($pregs), array_values($pregs), $input);
return nl2br($parsedtext);
return nl2br(strip_tags(stripslashes(htmlspecialchars($input))));
} |
|
|
| Back to top |
|
 |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Wed Dec 31, 2008 7:54 am Post subject: |
|
|
ok that works, thx, for [img] i put this
| Code: | | '/\[img\](.+)\[\/img\]/' => '<img src="$1">', | but it turns my page all wierd. and my entities wont work in my code tags.
EDIT: the images work but it turns my page blue and it needs to be black, but when i add another bit in the array it goes to normal.
i've tried
| Code: | | '/\<(.+)/' => '<', | but it didn't really bring my code tags back working again.
Last edited by deleted user 111213 on Wed Dec 31, 2008 7:58 am; edited 1 time in total |
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Wed Dec 31, 2008 7:58 am Post subject: |
|
|
Here I added [img]
| Code: | function topic($input){
$pregs = array(
'/\[b\](.+)\[\/b\]/' => '<b>$1</b>',
'/\[i\](.+)\[\/i\]/' => '<em>$1</em>',
'/\[u\](.+)\[\/u\]/' => '<u>$1</u>',
'/\[code\](.+)\[\/code\]/' => '<font style="padding:3px;" color="#CC0000" size="2">Code:</font><br><div id="code"><tt>$1</tt></div>',
'/\[url\](.+)\[\/url\]/' => '<a href="$1">$1</em>',
'/\[img\](.+)\[\/img\]/' => '<img src="$1" />'
);
$parsedtext = preg_replace(array_keys($pregs), array_values($pregs), $input);
return nl2br($parsedtext);
return nl2br(strip_tags(stripslashes(htmlspecialchars($input))));
} |
About the <, >... whatever chars...htmlspecialchars() is doing that already.
|
|
| Back to top |
|
 |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Wed Dec 31, 2008 8:03 am Post subject: |
|
|
| well maybe i should add htmlentities to that. and the [img] tag is excatly the same to what i did. the page has stayed the same.
|
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Wed Dec 31, 2008 8:06 am Post subject: |
|
|
| ghostrider1337 wrote: | | well maybe i should add htmlentities to that. and the [img] tag is excatly the same to what i did. the page has stayed the same. |
No, don't add it, replace it with htmlspecialchars.
I tried it with
| Code: | | echo topic("[img]http://lolwut.eu/images/lolwut.jpg[/img]"); |
And it works perfectly. But you may want to add a <br /> after the <img /> tag.
|
|
| Back to top |
|
 |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Wed Dec 31, 2008 9:19 am Post subject: |
|
|
i meant add htmlentites to the
return nl2br(strip_tags(stripslashes(htmlspecialchars($input))));
bit
EDIT: anyways, i'm going to leave bbcode for now. thanks for your help anyway reak. i appreciate it. i'll +rep you for your work, and your struggling effort to help me as i r noob.
|
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Wed Dec 31, 2008 9:41 am Post subject: |
|
|
No problem
Last tip:
Adding htmlentites to it makes no sense because it does the same as htmlspecialchars but more.
So just replace htmlspecialchars with htmlentites
| php.net: htmlentites wrote: | | This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities. |
|
|
| Back to top |
|
 |
|