how do I in php to get all the specific characters of a string

0

I need to get all 'SD' characters from within a string I'm using php function strpos and then making a substr in the position found in the string, however I need to get all of them since the position is varied.

//trazendo a darkness do template no banco
    $label = substr($qry['label_tpl_content'],7,5);
    $labels = substr($qry['label_tpl_content'],15,5);
    echo "<br>";
    $pos =  strpos($qry['label_tpl_content'],"SD");
    echo $pos;
    echo "<br>";
    echo $label."<br>";

this variable comes more or less like this

XA ^ 35 ~ SD10N ^ T0 ~ SD13 for example is not always in the same position.

    
asked by anonymous 08.05.2018 / 14:54

1 answer

0

If you just want to count the number of occurrences within the String, I suggest using the substr_count ()

PHP Documentation

    
08.05.2018 / 15:18