How in PHP regex to remove a string between two strings?

golfromeo

New member
I am coding a PHP pm system.

In it, when a user hits reply, the server adds a
to each end of the message so when the user replies, the old message will show up as a quote...

However, I only want there to be one trailing message.

Therefore, is there a way in PHP Regex to remove everything between the tags, and them remove the quote tags themselves?

For example, if the input was:

Here is my reply.
My first message

The output should be:
Here is my reply.
Thanks for the help, but when I do that, it just adds the quote on with the rest of it....

I just want EVERYTHING within the quotes deleted including the
itself, so if the input was:

Here is a reply.
my first message!

The output should be:

Here is my reply.
 
You can try this..

<?php

$test = '
This is a test
';

$extracted_text = ExtractText($test);

echo $extracted_text;

function ExtractText($user_input) {

$expression = "/^\[quote\](.*)\[\/quote\]$/";

$extracted = preg_replace($expression, "$1", $user_input);

return $extracted;

}

/*
Explanation of the regular expression:

/^\[quote\] ____ String starts with
(.*) ____ String Contains zero or more characters (saves the output into the first group).

\[\/quote\]$/ ____ String ends with
*/

?>

I hope this helps.
 
You can try this..

<?php

$test = '
This is a test
';

$extracted_text = ExtractText($test);

echo $extracted_text;

function ExtractText($user_input) {

$expression = "/^\[quote\](.*)\[\/quote\]$/";

$extracted = preg_replace($expression, "$1", $user_input);

return $extracted;

}

/*
Explanation of the regular expression:

/^\[quote\] ____ String starts with
(.*) ____ String Contains zero or more characters (saves the output into the first group).

\[\/quote\]$/ ____ String ends with
*/

?>

I hope this helps.
 
Back
Top