mardi 28 mars 2017

echo a conditional substring

I want to echo a conditional substring from:

<?php echo get_the_title(); ?>

The selector for my condition is " – " If the selector exists in the string, I want to echo as a substring the part behind the selector. If the selector doesn't exist, I want to echo the full string. Here is my idea, but I don't get it working:

if (($pos = strpos($data, " – ")) !== FALSE) {
$whatIWant = substr($data, $pos+1); 
}
echo $whatIWant; ?>

It is not working :-( What should I change to echo the conditional substring?

Aucun commentaire:

Enregistrer un commentaire