Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


bbcode problem [PHP]
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
LolSalad
Grandmaster Cheater
Reputation: 1

Joined: 26 Aug 2007
Posts: 988
Location: Australia

PostPosted: Wed Dec 31, 2008 4:14 am    Post subject: Reply with quote

You should seriously consider learning how to use regular expressions.

http://www.regular-expressions.info/

_________________
Back to top
View user's profile Send private message MSN Messenger
deleted user 111213
Grandmaster Cheater
Reputation: 0

Joined: 09 Nov 2007
Posts: 714

PostPosted: Wed Dec 31, 2008 4:37 am    Post subject: Reply with quote

but where the hell would i put it? in the <a href=> bit?
Back to top
View user's profile Send private message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Wed Dec 31, 2008 7:03 am    Post subject: Reply with quote

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
View user's profile Send private message
deleted user 111213
Grandmaster Cheater
Reputation: 0

Joined: 09 Nov 2007
Posts: 714

PostPosted: Wed Dec 31, 2008 7:27 am    Post subject: Reply with quote

uh, yea, that code doesn't work.
Back to top
View user's profile Send private message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Wed Dec 31, 2008 7:39 am    Post subject: Reply with quote

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
View user's profile Send private message
deleted user 111213
Grandmaster Cheater
Reputation: 0

Joined: 09 Nov 2007
Posts: 714

PostPosted: Wed Dec 31, 2008 7:54 am    Post subject: Reply with quote

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:
'/\<(.+)/' => '&lt;',
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
View user's profile Send private message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Wed Dec 31, 2008 7:58 am    Post subject: Reply with quote

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
View user's profile Send private message
deleted user 111213
Grandmaster Cheater
Reputation: 0

Joined: 09 Nov 2007
Posts: 714

PostPosted: Wed Dec 31, 2008 8:03 am    Post subject: Reply with quote

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
View user's profile Send private message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Wed Dec 31, 2008 8:06 am    Post subject: Reply with quote

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
View user's profile Send private message
deleted user 111213
Grandmaster Cheater
Reputation: 0

Joined: 09 Nov 2007
Posts: 714

PostPosted: Wed Dec 31, 2008 9:19 am    Post subject: Reply with quote

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
View user's profile Send private message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Wed Dec 31, 2008 9:41 am    Post subject: Reply with quote

No problem Wink

Last tip:
Adding htmlentites to it makes no sense because it does the same as htmlspecialchars but more.
So just replace htmlspecialchars with htmlentites Wink

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites