[PHP] preg_replace pains

2002-06-27 Thread Richard Davey

Hi all,

I've been having a wonderful night trying to solve this one, but I'm going
to throw in the towel and see if anyone else can shed some light on it. The
scenerio is quite simple, I'm parsing some form input from a user and
looking for the following:

[details]...[/details]

where the  can be any number of characters.

All I want to do is remove the whole section, including the [details] part.

So far I've got this working:

$message = preg_replace('\[details\].*?', , $message);

Which manages to find the opening tags (and remove them) but as soon as I
try to capture the closing tag (and all inbetween) it goes horribly wrong.
My last attempt looked like this:

$message = preg_replace('\[details\].*?\[/details\]', , $message);

This fails miserably. I'm fresh out of ideas and don't know enough about
regular expressions to be able to complete this task without some
assistance. ANY comments welcome!

Cheers,

Richard



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




RE: [PHP] preg_replace pains

2002-06-27 Thread John Holmes

Wouldn't you want to use preg_match() before you replace it?

www.php.net/preg_match

---John Holmes...

 -Original Message-
 From: Richard Davey [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, June 27, 2002 9:37 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] preg_replace pains
 
 Hi all,
 
 I've been having a wonderful night trying to solve this one, but I'm
going
 to throw in the towel and see if anyone else can shed some light on
it.
 The
 scenerio is quite simple, I'm parsing some form input from a user and
 looking for the following:
 
 [details]...[/details]
 
 where the  can be any number of characters.
 
 All I want to do is remove the whole section, including the [details]
 part.
 
 So far I've got this working:
 
 $message = preg_replace('\[details\].*?', , $message);
 
 Which manages to find the opening tags (and remove them) but as soon
as I
 try to capture the closing tag (and all inbetween) it goes horribly
wrong.
 My last attempt looked like this:
 
 $message = preg_replace('\[details\].*?\[/details\]', , $message);
 
 This fails miserably. I'm fresh out of ideas and don't know enough
about
 regular expressions to be able to complete this task without some
 assistance. ANY comments welcome!
 
 Cheers,
 
 Richard
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



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




Re: [PHP] preg_replace pains

2002-06-27 Thread Richard Davey

John Holmes [EMAIL PROTECTED] wrote in message
000a01c21e45$92b64270$b402a8c0@mango">news:000a01c21e45$92b64270$b402a8c0@mango...
 Wouldn't you want to use preg_match() before you replace it?

In this instance, no I don't think so. I've already performed the task I
needed with the tags in question and this is merely a clean-up to purge
out the string now I'm done with it. Except of course it's not working yet
:)

Cheers,

Richard




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




Re: [PHP] preg_replace pains

2002-06-27 Thread Analysis Solutions

Hi Richard:

On Fri, Jun 28, 2002 at 02:36:59AM +0100, Richard Davey wrote:

 [details]...[/details]
 $message = preg_replace('\[details\].*?', , $message);

You didn't state what you want to get out of this exercise.

To squash the detail tags and everything between them:
   $msg = preg_replace('/\[details][^[]*\[\/details]/', '', $msg);

To convert the [] delimiters to  delimiters:
   $msg = preg_replace('/\[(\/)?details]/', \\1 . 'details', $msg);

To drop everything outside the details:
   $msg = preg_replace('/.*(\[details][^[]*\[\/details]).*/', \\1, $msg);

Enjoy,

--Dan

-- 
   PHP classes that make web design easier
SQL Solution  |   Layout Solution   |  Form Solution
sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

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




Re: [PHP] preg_replace pains

2002-06-27 Thread Paul Roberts

try

$str = preg_replace(|\[details\].*?\[/details\]|si,, $str);

drop the i if you want it case sensitive.

Paul


Richard Davey [EMAIL PROTECTED] wrote in message 
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Hi all,
 
 I've been having a wonderful night trying to solve this one, but I'm going
 to throw in the towel and see if anyone else can shed some light on it. The
 scenerio is quite simple, I'm parsing some form input from a user and
 looking for the following:
 
 [details]...[/details]




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