2
I am trying, unsuccessfully to cut a string from a character contained in it, first I need to find the _
in the string, after finding it I need to cut the same one to it and after it to the ponto
, if you do not find the character I need to cut the string to the point.
Follow what I’ve tried so far;
Finding the character in the string:
$ID = '3803_452.jpg'; $termo = '_'; $padrao = '/' . $termo . '/'; if (preg_match($padrao, $ID)) { echo 'Tag encontrada'; } else { echo 'Tag não encontrada'; }
If there is no _
need to cut the string to the point playing in a variable, so:
$Id = 3803
If the _
I need to cut the string to it and after it to the point by playing each one in a variable.
Would something like this:
$Id = 3803;
$Seq = 452;
Hello @Sérgio, good morning, I appreciate the help, I’ll change the question, I don’t need the . jpg of the string, only the values.
– adventistapr
@adventistapr this was clear in the question. I had not noticed it well and now I have corrected.
– Sergio
I appreciate the great help.
– adventistapr
The
$seq = substr($seq, 0, strpos($seq, '.'));
can be done directly on$ID
since it is a party that does not matter. And also that the restriction of the question applies if you do not find the character need to crop the string to the point, then there won’t be$partes[1]
this will generate a Warning in PHP– Don't Panic
@Everson well seen! I corrected, thank you!
– Sergio
@Magichat you’re right. I fixed!
– Sergio
@Magichat is working. It must be an Ideone cache problem. I had tested by taking out the
_
and he kept thisstdout
... I clicked on Save again and cleaned.– Sergio