/    Sign up×
Community /Pin to ProfileBookmark

extracting delimited text from a string

Hi

how can i extract all the text inside the terms :
“#star” and “#end”, ?

thank´s in advance

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@SheldonOct 04.2006 — with out knowing more, as in how you are getting theses terms.

[code=php]
<?php

$var = "#star";
if(preg_match("#", $var)){
$new = preg_replace("#", "" , $var);
}else{
echo("Does not contain a #");
}

echo($var);
?>
[/code]




This may or may not work, untested.
Copy linkTweet thisAlerts:
@amrigoauthorOct 04.2006 — can i use just string functions ?

eg. : #start one text for test one text for test one text for test #end another text for test another text for test another text for test

so io get just :

one text for test one text for test one text for test
Copy linkTweet thisAlerts:
@SheldonOct 04.2006 — This may be what you want. Posted by Bokeh here -> http://www.webdeveloper.com/forum/showthread.php?t=123534

[code=php]
function find($start, $end, $string)
{
if(false !== ($pos = strpos(strtolower($string), strtolower($start))))
{
if($remove = stristr(($cropped = substr($string, $pos + strlen($start))), $end))
{
return trim(str_replace($remove, '', $cropped));
}
}
return false;
}

$string = "#start one text for test one text for test one text for test #end another text for test another text for test another text for test";
echo(find("#start", "#end", $string));
[/code]
×

Success!

Help @amrigo 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.25,
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,
)...