note 110714 deleted from function.substr by googleguy
| From: | googleguy@php.net | Date: | Tue, 27 Nov 2012 16:51:56 +0000 |
| Subject: | note 110714 deleted from function.substr by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192162@lists.php.net to get a copy of this message | ||
Note Submitter: nellsy at free dot fr
----
To substring a part of the text, with tag delimitation you could use a function like this
function fncSubstringBalise($text, $debBalise, $finBalise) {
$posDebut = strpos($text, $debBalise);
$posFin = strpos($text, $finBalise);
$debText = substr($text, 0, $posDebut);
$finText = substr($text, $posFin + 1);
$taille = strlen($text);
if ($posDebut === false && $posFin === false) {
$text = $text;
} else {
$text = $debText . $finText;
}
return $text;
}
Utilisation : fncSubstringBalise("toto fais {encore} du vélo", "{",
"}")
Example text : toto fais {encore} du vélo
Response : toto fais du vélo