So let’s say that I have the following code:
$var = '-77-randomtext-moretext.extension'
So that nothing in the variable is fixed, except for the hyphens ( – ), and the extension.
Then let’s say that I need to strore the ‘-77-‘ part as a string.
‘-77-‘ meaning anything in between the first two hyphens, including the hyphens themselves.
How could I do this?
The two primary ways to do that would be either
explodeorpreg_filter.Split:
preg_filter;
The
splitmethod is quicker, but less reliable.preg_filterwill ensure you always get either the data you want, or a NULL if it doesn’t exist, but requires more processing.