Click to See Complete Forum and Search --> : Remove all text between two symbols using php


SZero
07-19-2008, 04:09 AM
hi every1

am tryin to Remove all text between two symbols using php, for example i want to remove all text between the symbols < and >

ex:
I <aaaaaa> LIKE <asdf> W<aa>EBDEV<aaaa>ELOPER.com
Gives:
I LIKE WEBDEVELOPER.com

ty..

Znupi
07-19-2008, 05:44 AM
If you want to strip html tags (well, any <tags>)you can use the strip_tags() (http://php.net/strip-tags) function. If it's not only tags, let us know and we'll come up with some pattern most probably :)

SZero
07-19-2008, 05:56 AM
no not html tags

anyway i came up with sth

$first= preg_replace("/\[(\#[0-9A-F]{6}|[a-z]+)\]/si", "", $first_post);

but it doesn't remove (:) and (=)

???

ty

SZero
07-19-2008, 06:00 AM
actually doesn't remove any symbols or space, just letters

Znupi
07-19-2008, 07:07 AM
preg_replace("%<.*?>%", '', $first_post);

I'd test it but I'm at my girlfriend's house. Let us know if it works :)

SZero
07-19-2008, 09:18 AM
didn't work, it removes symbols from entire text not between <>

NogDog
07-19-2008, 09:33 AM
<?php
$text = "I <aaaaaa> LIKE <asdf> W<aa>EBDEV<aaaa>ELOPER.com";
echo preg_replace('/<[^>]*>/', '', $text);

Output:
I LIKE WEBDEVELOPER.com

SZero
07-19-2008, 10:26 AM
i modified it to be

$first= preg_replace("/\[(\#[0-9A-F]{6}|[a-z.=:?*1234567890]+)\]/si", "", $first_post);

it removes the symbols shown but not / and \
i tried putting them the same way but didn't work

SZero
07-19-2008, 11:10 AM
any1?

NogDog
07-19-2008, 11:31 AM
i modified it to be

$first= preg_replace("/\[(\#[0-9A-F]{6}|[a-z.=:?*1234567890]+)\]/si", "", $first_post);

it removes the symbols shown but not / and \
i tried putting them the same way but didn't work
What does this have to do with the requirement stated in the original post? If all you are doing is changing the <...> to [...], just change my last suggestion to:

preg_replace('/\[[^\]]*\]/', '', $text);

SZero
07-19-2008, 11:34 AM
i tried it didn't work
shows blank area

SZero
07-19-2008, 11:47 AM
actually it's

$first_post= preg_replace('/\[[^>]*\]/', '', $first_post);

worked TY:D

NogDog
07-19-2008, 12:03 PM
actually it's

$first_post= preg_replace('/\[[^>]*\]/', '', $first_post);

worked TY:D
That won't work if there happens to be a ">" within the square brackets.

<?php
$text = "This is [not]a test. It is[<really>] only a test.";
echo preg_replace('/\[[^\]]*\]/', '', $text);

Outputs:
This is a test. It is only a test.