Domanda

I got a simple php issue which is that I don't know how to use substring here...

ABCDEF[RAND NUMBER 1-10000000]GH

And so I need to get that random number using substring,

I dont know if my brain works correctly today but I really couldnt figure how to do that.

È stato utile?

Soluzione

Regex is always better in this case but If your string pattern is fixed like ABCDEF123456GH, you can simply use substr like

$str = "ABCDEF432465GH";
echo substr($str, 6, -2);

Altri suggerimenti

This will do, no need for substr or anything:

$string='ABCDEF432465GH';
echo preg_replace('/[a-z\[\] ]*/i', '', $string);

https://eval.in/136918

Regular expressions are better when you don't know where in the text is desired substring,

$string = "ABCDEF10000000GH";

if (preg_match("/(\d+)/", $string, $m)) {
  print $m[1];
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top