preg_replace help!

preg_replace help!

am 03.05.2006 23:25:57 von Nathan Heaps

> Hey, I need some help.
> I am trying to parse a forum post using php, but it parses it everytime it
> sees the letter, not the thing in quotes. Any help?
>
> function bbcodereplace($subject){
> // $document should contain an HTML document.
> // This will remove HTML tags, javascript sections
> // and white space. It will also convert some
> // common HTML entities to their text equivalent.
> $search = array ("[b]", // Bold
> "[u]", // Underline
> "[i]", // Italics
> "[/b]", // Bold Close
> "[/u]", // Underline Close
> "[/i]"); // Italics Close
> // '@&(gt|#62);@i',
> // '@&(nbsp|#160);@i',
> // '@&(iexcl|#161);@i',
> // '@&(cent|#162);@i',
> // '@&(pound|#163);@i',
> // '@&(copy|#169);@i',
> // '@&#(\d+);@e'); // evaluate as php
>
> $replace = array ('',
> '',
> '',
> '
',
> '
',
> '
');
> // '>',
> // ' ',
> // chr(161),
> // chr(162),
> // chr(163),
> // chr(169),
> // 'chr(\1)');
>
> return preg_replace($search, $replace, $subject);
> }
>
> PLEASE NOTE: This is for a phpBB forum, not vBulliten or
> InvisionPowerBoard
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: preg_replace help!

am 04.05.2006 01:46:45 von John Hicks

Nathan Heaps wrote:
>> I am trying to parse a forum post using php, but it parses it
>> everytime it
>> sees the letter, not the thing in quotes.

What letter? What thing in quotes?

-J

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: preg_replace help!

am 04.05.2006 02:08:10 von Nathan Heaps

Wait, its a different thing now. You see, I am trying to replace phpbb's
bbcode with working html code, but what makes it hard is that phpbb inserts
a number after SOME of the bbcode tags. Here is what I have so far:
function bbcodereplace($subject){
$search = array ("/\[url=(\W?)(.*?)(\W?)\](.*?)\[\/url\]/",
// "/\[i(.*?)\](.*?)\[\/i(.*?)\]/", // Italics
"/\[u(.*?)\](.*?)\[\/u(.*?)\]/", // Underline
"/\[img(.*?)\](.*?)\[\/img(.*?)\]/", // Image
"/\[b(.*?)\](.*?)\[\/b(.*?)\]/"); // Bold
// '@&(gt|#62);@i',
// '@&(nbsp|#160);@i',
// '@&(iexcl|#161);@i',
// '@&(cent|#162);@i',
// '@&(pound|#163);@i',
// '@&(copy|#169);@i',
// '@&#(\d+);@e'); // evaluate as php

$replace = array ('',
// '$2',
'$2',
'',
'$2');
// '',
// '',
// '
',
// '
');
// '>',
// ' ',
// chr(161),
// chr(162),
// chr(163),
// chr(169),
// 'chr(\1)');

return preg_replace($search, $replace, $subject);
}

my problem is that if I un-comment the italic thing, then image doesn't
work. any idea on how to fix it?
----- Original Message -----
From: "John Hicks"
To: "Nathan Heaps"
Cc:
Sent: Wednesday, May 03, 2006 7:46 PM
Subject: Re: [PHP-DB] preg_replace help!


> Nathan Heaps wrote:
>>> I am trying to parse a forum post using php, but it parses it everytime
>>> it
>>> sees the letter, not the thing in quotes.
>
> What letter? What thing in quotes?
>
> -J

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: preg_replace help!

am 04.05.2006 04:17:52 von Liber

// "/\[i(.*?)\](.*?)\[\/i(.*?)\]/", // Italics
"/\[u(.*?)\](.*?)\[\/u(.*?)\]/", // Underline
"/\[img(.*?)\](.*?)\[\/img(.*?)\]/", // Image
"/\[b(.*?)\](.*?)\[\/b(.*?)\]/"); // Bold

Change to

"/\[i:(.*?)\](.*?)\[\/i:(.*?)\]/", // Italics
"/\[u:(.*?)\](.*?)\[\/u:(.*?)\]/", // Underline
"/\[img:(.*?)\](.*?)\[\/img:(.*?)\]/", // Image
"/\[b:(.*?)\](.*?)\[\/b:(.*?)\]/"); // Bold

-----Original Message-----
From: Nathan Heaps [mailto:nathan42100@student.com]
Sent: Thursday, May 04, 2006 8:08 AM
To: John Hicks
Cc: php-db@lists.php.net
Subject: Re: [PHP-DB] preg_replace help!

Wait, its a different thing now. You see, I am trying to replace phpbb's
bbcode with working html code, but what makes it hard is that phpbb inserts
a number after SOME of the bbcode tags. Here is what I have so far:
function bbcodereplace($subject){
$search = array ("/\[url=(\W?)(.*?)(\W?)\](.*?)\[\/url\]/",
// "/\[i(.*?)\](.*?)\[\/i(.*?)\]/", // Italics
"/\[u(.*?)\](.*?)\[\/u(.*?)\]/", // Underline
"/\[img(.*?)\](.*?)\[\/img(.*?)\]/", // Image
"/\[b(.*?)\](.*?)\[\/b(.*?)\]/"); // Bold
// '@&(gt|#62);@i',
// '@&(nbsp|#160);@i',
// '@&(iexcl|#161);@i',
// '@&(cent|#162);@i',
// '@&(pound|#163);@i',
// '@&(copy|#169);@i',
// '@&#(\d+);@e'); // evaluate as php

$replace = array ('',
// '$2',
'$2',
'',
'$2');
// '',
// '',
// '
',
// '
');
// '>',
// ' ',
// chr(161),
// chr(162),
// chr(163),
// chr(169),
// 'chr(\1)');

return preg_replace($search, $replace, $subject); }

my problem is that if I un-comment the italic thing, then image doesn't
work. any idea on how to fix it?
----- Original Message -----
From: "John Hicks"
To: "Nathan Heaps"
Cc:
Sent: Wednesday, May 03, 2006 7:46 PM
Subject: Re: [PHP-DB] preg_replace help!


> Nathan Heaps wrote:
>>> I am trying to parse a forum post using php, but it parses it
>>> everytime it sees the letter, not the thing in quotes.
>
> What letter? What thing in quotes?
>
> -J

--
PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: preg_replace help!

am 04.05.2006 04:30:07 von Nathan Heaps

nevermind, I got it fixed. Just had to rearrange it. it was sensing the i in
img as italic so if you put it first it would work.
----- Original Message -----
From: "Liber"
To: "'Nathan Heaps'" ; "'John Hicks'"

Cc:
Sent: Wednesday, May 03, 2006 10:17 PM
Subject: RE: [PHP-DB] preg_replace help!


>
> // "/\[i(.*?)\](.*?)\[\/i(.*?)\]/", // Italics
> "/\[u(.*?)\](.*?)\[\/u(.*?)\]/", // Underline
> "/\[img(.*?)\](.*?)\[\/img(.*?)\]/", // Image
> "/\[b(.*?)\](.*?)\[\/b(.*?)\]/"); // Bold
>
> Change to
>
> "/\[i:(.*?)\](.*?)\[\/i:(.*?)\]/", // Italics
> "/\[u:(.*?)\](.*?)\[\/u:(.*?)\]/", // Underline
> "/\[img:(.*?)\](.*?)\[\/img:(.*?)\]/", // Image
> "/\[b:(.*?)\](.*?)\[\/b:(.*?)\]/"); // Bold
>
> -----Original Message-----
> From: Nathan Heaps [mailto:nathan42100@student.com]
> Sent: Thursday, May 04, 2006 8:08 AM
> To: John Hicks
> Cc: php-db@lists.php.net
> Subject: Re: [PHP-DB] preg_replace help!
>
> Wait, its a different thing now. You see, I am trying to replace phpbb's
> bbcode with working html code, but what makes it hard is that phpbb
> inserts
> a number after SOME of the bbcode tags. Here is what I have so far:
> function bbcodereplace($subject){
> $search = array ("/\[url=(\W?)(.*?)(\W?)\](.*?)\[\/url\]/",
> // "/\[i(.*?)\](.*?)\[\/i(.*?)\]/", // Italics
> "/\[u(.*?)\](.*?)\[\/u(.*?)\]/", // Underline
> "/\[img(.*?)\](.*?)\[\/img(.*?)\]/", // Image
> "/\[b(.*?)\](.*?)\[\/b(.*?)\]/"); // Bold
> // '@&(gt|#62);@i',
> // '@&(nbsp|#160);@i',
> // '@&(iexcl|#161);@i',
> // '@&(cent|#162);@i',
> // '@&(pound|#163);@i',
> // '@&(copy|#169);@i',
> // '@&#(\d+);@e'); // evaluate as php
>
> $replace = array ('',
> // '$2',
> '$2',
> '',
> '$2');
> // '',
> // '',
> // '
',
> // '
');
> // '>',
> // ' ',
> // chr(161),
> // chr(162),
> // chr(163),
> // chr(169),
> // 'chr(\1)');
>
> return preg_replace($search, $replace, $subject); }
>
> my problem is that if I un-comment the italic thing, then image doesn't
> work. any idea on how to fix it?
> ----- Original Message -----
> From: "John Hicks"
> To: "Nathan Heaps"
> Cc:
> Sent: Wednesday, May 03, 2006 7:46 PM
> Subject: Re: [PHP-DB] preg_replace help!
>
>
>> Nathan Heaps wrote:
>>>> I am trying to parse a forum post using php, but it parses it
>>>> everytime it sees the letter, not the thing in quotes.
>>
>> What letter? What thing in quotes?
>>
>> -J
>
> --
> PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit:
> http://www.php.net/unsub.php
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: preg_replace help!

am 04.05.2006 04:45:22 von Nathan Heaps

Ok, scratch that, new problem. what can I replace (.*?) with in order for
php to recognise a multi-line quote/bold/italic/code/whatever?
----- Original Message -----
From: "Liber"
To: "'Nathan Heaps'" ; "'John Hicks'"

Cc:
Sent: Wednesday, May 03, 2006 10:17 PM
Subject: RE: [PHP-DB] preg_replace help!


>
> // "/\[i(.*?)\](.*?)\[\/i(.*?)\]/", // Italics
> "/\[u(.*?)\](.*?)\[\/u(.*?)\]/", // Underline
> "/\[img(.*?)\](.*?)\[\/img(.*?)\]/", // Image
> "/\[b(.*?)\](.*?)\[\/b(.*?)\]/"); // Bold
>
> Change to
>
> "/\[i:(.*?)\](.*?)\[\/i:(.*?)\]/", // Italics
> "/\[u:(.*?)\](.*?)\[\/u:(.*?)\]/", // Underline
> "/\[img:(.*?)\](.*?)\[\/img:(.*?)\]/", // Image
> "/\[b:(.*?)\](.*?)\[\/b:(.*?)\]/"); // Bold
>
> -----Original Message-----
> From: Nathan Heaps [mailto:nathan42100@student.com]
> Sent: Thursday, May 04, 2006 8:08 AM
> To: John Hicks
> Cc: php-db@lists.php.net
> Subject: Re: [PHP-DB] preg_replace help!
>
> Wait, its a different thing now. You see, I am trying to replace phpbb's
> bbcode with working html code, but what makes it hard is that phpbb
> inserts
> a number after SOME of the bbcode tags. Here is what I have so far:
> function bbcodereplace($subject){
> $search = array ("/\[url=(\W?)(.*?)(\W?)\](.*?)\[\/url\]/",
> // "/\[i(.*?)\](.*?)\[\/i(.*?)\]/", // Italics
> "/\[u(.*?)\](.*?)\[\/u(.*?)\]/", // Underline
> "/\[img(.*?)\](.*?)\[\/img(.*?)\]/", // Image
> "/\[b(.*?)\](.*?)\[\/b(.*?)\]/"); // Bold
> // '@&(gt|#62);@i',
> // '@&(nbsp|#160);@i',
> // '@&(iexcl|#161);@i',
> // '@&(cent|#162);@i',
> // '@&(pound|#163);@i',
> // '@&(copy|#169);@i',
> // '@&#(\d+);@e'); // evaluate as php
>
> $replace = array ('',
> // '$2',
> '$2',
> '',
> '$2');
> // '',
> // '',
> // '
',
> // '
');
> // '>',
> // ' ',
> // chr(161),
> // chr(162),
> // chr(163),
> // chr(169),
> // 'chr(\1)');
>
> return preg_replace($search, $replace, $subject); }
>
> my problem is that if I un-comment the italic thing, then image doesn't
> work. any idea on how to fix it?
> ----- Original Message -----
> From: "John Hicks"
> To: "Nathan Heaps"
> Cc:
> Sent: Wednesday, May 03, 2006 7:46 PM
> Subject: Re: [PHP-DB] preg_replace help!
>
>
>> Nathan Heaps wrote:
>>>> I am trying to parse a forum post using php, but it parses it
>>>> everytime it sees the letter, not the thing in quotes.
>>
>> What letter? What thing in quotes?
>>
>> -J
>
> --
> PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit:
> http://www.php.net/unsub.php
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: preg_replace help!

am 04.05.2006 17:32:50 von Martin Alterisio

------=_Part_89436_7477258.1146756770252
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

2006/5/3, Nathan Heaps :
>
> Ok, scratch that, new problem. what can I replace (.*?) with in order for
> php to recognise a multi-line quote/bold/italic/code/whatever?


By default the "." pattern matches anything except a line break you can
either use ((?:.|\n)*) or add a modifier to the regular expression that
changes the behaviour of the "." pattern. Modifiers are appended at the end
of the regular expression, after the closing delimiter:

/\[i:(.*?)\](.*?)\[\/i:(.*?)\]/s


The "s" modifier tells the regular expression to captura any character with
an "." pattern. With only this you should be able to captura multiline tags=
..


Also you should consider using the "U" modifier which makes all repetition
patters (*,+) ungreedy. This way you can avoid using the "?" after

------=_Part_89436_7477258.1146756770252--

Re: preg_replace help!

am 04.05.2006 17:34:32 von Martin Alterisio

------=_Part_89478_5500571.1146756872390
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

2006/5/4, Martin Alterisio :
>
> 2006/5/3, Nathan Heaps :
>
> > Ok, scratch that, new problem. what can I replace (.*?) with in order
> > for
> > php to recognise a multi-line quote/bold/italic/code/whatever?
>
>
> By default the "." pattern matches anything except a line break you can
> either use ((?:.|\n)*) or add a modifier to the regular expression that
> changes the behaviour of the "." pattern. Modifiers are appended at the e=
nd
> of the regular expression, after the closing delimiter:
>
> /\[i:(.*?)\](.*?)\[\/i:(.*?)\]/s
>
>
> The "s" modifier tells the regular expression to captura any character
> with an "." pattern. With only this you should be able to captura multili=
ne
> tags.
>
> Also you should consider using the "U" modifier which makes all repetitio=
n
> patters (*,+) ungreedy. This way you can avoid using the "?" after
>


Sorry, las message wasn't send properly (gmail isn't working right anymore
for me). The last part was cutoff, it said:

Also you should consider using the "U" modifier which makes all repetition
patters (*,+) ungreedy. This way you can avoid using the "?" after all
repeated patterns:

/\[i:(.*)\](.*)\[\/i:(.*)\]/sU

------=_Part_89478_5500571.1146756872390--

Re: preg_replace help!

am 04.05.2006 21:52:28 von Nathan Heaps

thanks, its fixed now!!!
----- Original Message -----
From: Martin Alterisio
To: Nathan Heaps
Cc: Liber ; John Hicks ; php-db@lists.php.net
Sent: Thursday, May 04, 2006 11:34 AM
Subject: Re: [PHP-DB] preg_replace help!





2006/5/4, Martin Alterisio :
2006/5/3, Nathan Heaps :
Ok, scratch that, new problem. what can I replace (.*?) with in order for
php to recognise a multi-line quote/bold/italic/code/whatever?


By default the "." pattern matches anything except a line break you can
either use ((?:.|\n)*) or add a modifier to the regular expression that
changes the behaviour of the "." pattern. Modifiers are appended at the end
of the regular expression, after the closing delimiter:

/\[i:(.*?)\](.*?)\[\/i:(.*?)\]/s


The "s" modifier tells the regular expression to captura any character with
an "." pattern. With only this you should be able to captura multiline tags.

Also you should consider using the "U" modifier which makes all repetition
patters (*,+) ungreedy. This way you can avoid using the "?" after



Sorry, las message wasn't send properly (gmail isn't working right anymore
for me). The last part was cutoff, it said:

Also you should consider using the "U" modifier which makes all repetition
patters (*,+) ungreedy. This way you can avoid using the "?" after all
repeated patterns:

/\[i:(.*)\](.*)\[\/i:(.*)\]/sU

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php