Page 1 of 1

str_replace query

Posted: Fri Jul 06, 2007 8:02 am
by ashleek007
Hey,

I've got a url like this....

dpages/38/test1.php

I want to remove everything from this string so i am left with just: -

38

I know I need to use the str_replace function, but i cant seem to get it working properly...

Is there a simple one liner that can do this... to strip all before, after and including the '/'...

Cheers,
Ash :roll:

Posted: Fri Jul 06, 2007 8:15 am
by Gente

Code: Select all

<?php
$string = 'dpages/38/test1.php';
$start = strpos($string, '/') + 1;
$len = strrpos($string, '/') - $start;
echo substr($string, $start, $len);
?>

Posted: Fri Jul 06, 2007 8:15 am
by ashleek007

Code: Select all

$url_id = $row['url'];
$url_id = explode('/', $url_id, 3);
echo $url_id[1];
thats what ive found works.... the explode() function...

Ash