extract string followed by escape character

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
veenasv
Forum Newbie
Posts: 8
Joined: Wed Aug 20, 2003 11:15 am

extract string followed by escape character

Post 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?
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post 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];
}
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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);
?>
Post Reply