php reg ex. delete piece of text


I am trying to delete an unknown piece of text from a string, but i cannot seem to get the reg expr. right...

The text i would like to delete is the text between the 'start' and the 'stop' words.
Thanks in advance.

My (not workin) code thus far:
<?php
$html = 'Lorem start ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor 
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris 
nisi ut aliquip ex ea stop commodo consequat.' ;

$html_stripped = preg_replace("/^start(.+)stop$/m", "", $html);
?>

Open in new window

dwaxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kumaranmcaCommented:
Try the below code..its resolve your problem...

if you need remove the text add in array

$html_stripped = str_replace(array('start','stop'), "", $html);
<?php
$html = 'Lorem start ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor 
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris 
nisi ut aliquip ex ea stop commodo consequat.' ;

$html_stripped = str_replace(array('start','stop'), "", $html);
echo $html_stripped;
?>

Open in new window

0
dwaxAuthor Commented:
Thanks for your quick reply.

The code you provided will delete the two words, but i would like to delete the text between the two words (which can be anything, plain text, html code etc).

So it needs to delete anything between the two words.
0
kumaranmcaCommented:
Sorry, Try this code...its resolve your problem...


<?php
$html = 'Lorem start ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor 
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris 
nisi ut aliquip ex ea stop commodo consequat.' ;


echo preg_replace('/start[^>]*stop/', '', $html);
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dwaxAuthor Commented:
Yes!
Thanks kumaranmca!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.