/    Sign up×
Community /Pin to ProfileBookmark

Remove all text between two symbols using php

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..

to post a comment
PHP

12 Comments(s)

Copy linkTweet thisAlerts:
@ZnupiJul 19.2008 — If you want to strip html tags (well, any <tags>)you can use the [url=http://php.net/strip-tags]strip_tags()[/URL] function. If it's not only tags, let us know and we'll come up with some pattern most probably ?
Copy linkTweet thisAlerts:
@SZeroauthorJul 19.2008 — 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
Copy linkTweet thisAlerts:
@SZeroauthorJul 19.2008 — actually doesn't remove any symbols or space, just letters
Copy linkTweet thisAlerts:
@ZnupiJul 19.2008 — [code=php]
preg_replace("%<.*?>%", '', $first_post);
[/code]

I'd test it but I'm at my girlfriend's house. Let us know if it works ?
Copy linkTweet thisAlerts:
@SZeroauthorJul 19.2008 — didn't work, it removes symbols from entire text not between <>
Copy linkTweet thisAlerts:
@NogDogJul 19.2008 — [code=php]
<?php
$text = "I <aaaaaa> LIKE <asdf> W<aa>EBDEV<aaaa>ELOPER.com";
echo preg_replace('/<[^>]*>/', '', $text);
[/code]

Output:
I LIKE WEBDEVELOPER.com[/quote]
Copy linkTweet thisAlerts:
@SZeroauthorJul 19.2008 — 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
Copy linkTweet thisAlerts:
@SZeroauthorJul 19.2008 — any1?
Copy linkTweet thisAlerts:
@NogDogJul 19.2008 — 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[/QUOTE]

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:
[code=php]
preg_replace('/[[^]]*]/', '', $text);
[/code]
Copy linkTweet thisAlerts:
@SZeroauthorJul 19.2008 — i tried it didn't work

shows blank area
Copy linkTweet thisAlerts:
@SZeroauthorJul 19.2008 — actually it's

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

worked TY?
Copy linkTweet thisAlerts:
@NogDogJul 19.2008 — actually it's

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

worked TY?[/QUOTE]

That won't work if there happens to be a ">" within the square brackets.
[code=php]
<?php
$text = "This is [not]a test. It is[<really>] only a test.";
echo preg_replace('/[[^]]*]/', '', $text);
[/code]

Outputs:

[indent]This is a test. It is only a test.[/indent]
×

Success!

Help @SZero spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...