Page 1 of 1

extract string followed by escape character

Posted: Wed Sep 03, 2003 1:46 pm
by veenasv
Hi,
Is it possible to extract the remaining string followed by the escape character.
Ex: string x6a-s_14, x6a-s_1 etc.,
I need to get the last interger part i.e 14, 1 respectively
Is this possible?

Posted: Wed Sep 03, 2003 3:40 pm
by xisle
you could explode string on comma, loop through that array and then explode on underscore...

http://www.php.net/manual/en/function.explode.php

kinda like this..

Code: Select all

$firstarray=explode("," $originalstring);
foreach($firstarray as $key=>$val){
    $secondarray=explode("_" $val);
    echo $secondarrayї1];
}

Posted: Wed Sep 03, 2003 8:52 pm
by JAM
Or continue tweaking:

Code: Select all

<?php
$string = ' x6a-s_14, x6a-s_1, x6a-s_14, x6a-s_14, x6a-s_144, x6a-s_1234';
$array = explode(",",str_replace('x6a-s_','',$string));
print_r($array);
?>