hey up people.
right i have a string (a link) to a certain picture.
for example:
"pictures/1/1/3.jpg"
and what i want to do is to split it at the second slash so that everything to the left ('pictures/1/')goes in array0 and everything to the right ('1/3.jpg')goes in array1. is this possible at all?! im tryin to find easier ways other than explode, joining them all together, etc.
cheers for any help,
chris.
string splitting into arrays
Moderator: General Moderators
-
noaksey2000
- Forum Newbie
- Posts: 5
- Joined: Sun Aug 17, 2003 10:29 am
Dependant on the string your trying to match this may work...
Will result in...
[0] = Entire match part of the string
[1] = Everything upto and including second slash
[2] = the remaining part of the link
Code: Select all
<?php
$string_in = '<a href="pictures/1/1/3.jpg">';
preg_match('/([^"]+\w+\/\d+\/)(\d+\/[^"]+)/', $string_in, $match);
print_r($match);
?>Code: Select all
Array
(
ї0] => pictures/1/1/3.jpg
ї1] => pictures/1/
ї2] => 1/3.jpg
)[1] = Everything upto and including second slash
[2] = the remaining part of the link