cereal
Veteran Poster
1,196 posts since Aug 2007
Reputation Points: 358
Solved Threads: 232
Skill Endorsements: 22
If you need two segments, use explode():
<?php
$a = '/blablabla/123123';
$b = explode('/',$a);
echo $b[2];
?>
If you need a single string then use str_replace():
<?php
$a = '/blablabla/123123';
$b = str_replace('/','',$a);
echo $b;
?>
;)
cereal
Veteran Poster
1,196 posts since Aug 2007
Reputation Points: 358
Solved Threads: 232
Skill Endorsements: 22
$str = "//abdhbw/1234/acljk/5678/qacjk";
echo preg_replace("/[\D]+)/","",$str);
You don't state whether you want the values into an array or whether you just want one long string of numbers. The code gives long number.
If you're certain you don't have any values like /0/, you can use this to put them into an array:
$str = "//abdhBw/1234/acljk/5678/qacjk";
$r = array_filter(preg_split("/[\D]+/",$str));
print_r($r);
But just in case, you can do this:
$str = "//abdhBw/1234/acl0jk/5678/qacjk";
preg_match_all("/[\d]+/",$str,$matches);
print_r($matches[0]);
diafol
Keep Smiling
10,839 posts since Oct 2006
Reputation Points: 1,675
Solved Threads: 1,536
Skill Endorsements: 61
Oh, now I understand what you where asking for.. :D
cereal
Veteran Poster
1,196 posts since Aug 2007
Reputation Points: 358
Solved Threads: 232
Skill Endorsements: 22
Maybe cut on '/' and check the contents for integer type.
$t = "/aldscb1234wder/q1274/12643yujo/243724/";
$partz = explode("/",$t);
foreach($partz as $part){
if(preg_match("/^\d+$/",$part)){
$new_r[] = $part;
}
}
print_r($new_r);
or even:
$t = "/aldscb1234wder/123//q1274/12643yujo/243724/";
preg_match_all("/\/\d+\//",$t,$matches);
$r = str_replace("/","",$matches[0]);
print_r($r);
however, this won't be positive for start of string or end of string numbers unless there are / at start and end.
EDIT:
OK fixed
$t = "123/aldscb1234wder///1274/12643yujo/243724/q23";
preg_match_all("/(\b|\/)\d+(\b|\/)/",$t,$matches);
$r = str_replace("/","",$matches[0]);
print_r($r);
THat will return integers at the start and end of your string.
diafol
Keep Smiling
10,839 posts since Oct 2006
Reputation Points: 1,675
Solved Threads: 1,536
Skill Endorsements: 61
OK, mark as solved with the link below the edit box.
diafol
Keep Smiling
10,839 posts since Oct 2006
Reputation Points: 1,675
Solved Threads: 1,536
Skill Endorsements: 61