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

Asked

Viewed 89 times

0

I need to take all 'SD' characters from inside a string I am using the php strpos function and then making a substr in the position found in the string, but I need to take all because 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 some more or less like this

XA 35~SD10N T0~SD13 for example, but not always in the same position.

  • You want to know how often the word 'sd' appears, or its positions?

  • you want to count the number? or you want to remove the occurrences?

1 answer

0

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

PHP documentation

Browser other questions tagged

You are not signed in. Login or sign up in order to post.