Hello everyone... I need help with some PHP script i am working on - i need help to get the best way to do this: //this is what i get in the POST $full_number = '1234123121'; //i need to make this as output: $number = '41'; basically i am looking for some way, maybe using str_replace() to get the script to count 123 and output the first two charters after it... the full number is dynamic.. Thanks.
It's difficult to say without more info. Are you always looking for "123"? Whatever is after "123" is always 2 chars long? You can extract strings with substr: http://php.net/manual/en/function.substr.php
$number = '12312312312312341123123123133'; $numtofind = '41'; $pos = strpos($numtofind, $number); $str = subtr($number, $pos, strlen($numtofind)); echo $str; PHP: This finds the position of '41' in the string using strpos. It then uses substr to create a sub-string that is x characters long (based on the length of the string we're looking for) at the position of the search.
$number = substr($full_number, 3, 2); To future proof my answer, PHP 6 would be $number = $full_number[3,2];
Thanks for the fast replay... well... sorry i didnt explain it right the full number is dynamic but his length is 10-15 numbers... i need to output the 4th and 5th numbers from left only...
Can I ask what he is doing this for? Is it for encryption? I mean - what is the point in looking for that particular part of the string? } [/QUOTE]