How to extract data between strings
Collapse
X
-
for 65002-xh0dICiqQSPHP Code:preg_match('/[A-z]{1}-(.*)-[0-9]{1}\.[A-z]{3,4}/', $text, $matches);
andfor 65002PHP Code:preg_match('/-(\d+)-/', $text, $matches);
Leave a comment:
-
Originally posted by sladex View PostHmm...it's working for one file, but when I have all list of files, its not working.
Let's say I have list of files:
And if I using that code:Code:P-100208-UpYdMeMtcm-1.jpg P-100216-4MwGRw5swv-1.jpg P-100217-suHqW1kFOf-1.jpg P-100218-wsgX3Y8v77-1.jpg P-100219-Feclv8jfVk-1.jpg P-100220-Pc6D8F7JNd-1.jpg P-10054-2zWg4pJOid-1.jpg P-100896-LbV5S2p98S-1.jpg P-100897-02YW6j9jst-1.jpg P-100899-VxvwjVdxbW-1.jpg P-100901-3oICxPu8Ul-1.jpg P-100902-hR3wqSFoC4-1.jpg P-100908-aICRXta8R2-1.jpg P-100910-xKo8CiuVuv-1.jpg P-100912-9M4YoqvxNX-1.jpg P-100914-gxT7upzalv-1.jpg P-100918-wPkDryqSjm-1.jpg etc...
Then Is exploding onlyPHP Code:<?php
if ($handle = opendir('games/screen/4/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$wordChunksLimited = explode("-", $file);
echo "$wordChunksLimited[0]\n";
}
}
closedir($handle);
}
?>
Do anyone have solution for this?Code:P P P P P etc..
Thank You.PHP Code:<?php
//assuming you have "P-100208-UpYdMeMtcm-1.jpg" in that directory,
if ($handle = opendir('games/screen/4/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$wordChunksLimited = explode("-", $file);
echo $wordChunksLimited[2]."\n"; // $wordChunksLimited[0] would be "P", $wordChunksLimited[1] would be "100208", $wordChunksLimited[2] would be "UpYdMeMtcm" and $wordChunksLimited[3] would be "1"... explode function returns an array
}
}
closedir($handle);
}
?>
Leave a comment:
-
Hmm...it's working for one file, but when I have all list of files, its not working.
Let's say I have list of files:
And if I using that code:Code:P-100208-UpYdMeMtcm-1.jpg P-100216-4MwGRw5swv-1.jpg P-100217-suHqW1kFOf-1.jpg P-100218-wsgX3Y8v77-1.jpg P-100219-Feclv8jfVk-1.jpg P-100220-Pc6D8F7JNd-1.jpg P-10054-2zWg4pJOid-1.jpg P-100896-LbV5S2p98S-1.jpg P-100897-02YW6j9jst-1.jpg P-100899-VxvwjVdxbW-1.jpg P-100901-3oICxPu8Ul-1.jpg P-100902-hR3wqSFoC4-1.jpg P-100908-aICRXta8R2-1.jpg P-100910-xKo8CiuVuv-1.jpg P-100912-9M4YoqvxNX-1.jpg P-100914-gxT7upzalv-1.jpg P-100918-wPkDryqSjm-1.jpg etc...
Then Is exploding onlyPHP Code:<?php
if ($handle = opendir('games/screen/4/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$wordChunksLimited = explode("-", $file);
echo "$wordChunksLimited[0]\n";
}
}
closedir($handle);
}
?>
Do anyone have solution for this?Code:P P P P P etc..
Thank You.
Leave a comment:
-
How to extract data between strings
Hi,
Can you help me with that.
I'm tried few times, but failed.
I want to extract numbers from the name of file.
File name':P-65002-xh0dICiqQS-1.jpg
How to get these numbers between P- and - ?
I tried like that:
But I'm sure that part: preg_match("P-(.*)-" has to be changed.PHP Code:<?php
$text = 'P-65002-xh0dICiqQS-1.jpg';
preg_match("P-(.*)-", $text, $matches);
$value = $matches[1];
echo"$value";
?>
I don't know parrameter that should go there.
Can anyone help me with that?
Thank You very much.Tags: None
Leave a comment: