|
Posted by robert on 04/26/06 20:53
"MattMika" <mattmika@hotmail.com> wrote in message
news:u5av42t25svkgf0ihfsul60a9ldgeo5s43@4ax.com...
| Can anyone explain this to me?
|
| $string = "United Parcel Service (1 x 0.55lbs) (Ground):";
|
| $start = strrpos($string, '('); // =36
| $end = strrpos($string, ')'); // =43
| $editstring = substr($string, $start, $end);// should be strpos 36-43
|
| echo $editstring;
|
| returns - (Ground):
|
| I'm not sure why the colon is showing up. Is there a better way to
| extract the shipping type from this string?
the key is the length of characters after the starting point...you're
telling it to grab the next 43 characters that follow position 36. have a
look:
<?
$string = "United Parcel Service (1 x 0.55lbs) (Ground):";
$start = strrpos($string, '(');
$end = strrpos($string, ')');
$result = substr($string, $start, $end);
$length = ($end + 1) - $start; // 1 is offset
$expectedResult = substr($string, $start, $length);
echo '<pre>' .
print_r(
array(
'search' => $string ,
'start' => $start ,
'end' => $end ,
'length' => $length ,
'using just end' => $result ,
'using LENGTH' => $expectedResult
),
true
) .
'</pre>';
?>
hth,
me
Navigation:
[Reply to this message]
|