PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
ryanrbftp
Forum Newbie
Posts: 8 Joined: Thu Jun 15, 2006 1:47 pm
Post
by ryanrbftp » Thu Jun 15, 2006 1:54 pm
Using PHP, If I had the following string:
original and flight model "Robert Versluys" repaint in Air Dolomiti by "Massimo Grassi" full 3 d texture,movimg parts,night effects<br><img src="/images/aircraft/fs2002civiljets/airdccrj2.jpg" width="150" height="112">
How could I extract only
/images/aircraft/fs2002civiljets/airdccrj2.jpg
and continue using it im my script? Please bear in mind that the image files change, as well as the DIR's for the images, so perhaps start extracting with the starting point of
<img
and finishing with
>
Any ideas guys?
printf
Forum Contributor
Posts: 173 Joined: Wed Jan 12, 2005 5:24 pm
Post
by printf » Thu Jun 15, 2006 2:36 pm
Just use any of the preg_ functions that best fit your needs....
example... (preg_match_all) match more than one occurrence
Code: Select all
<?
$data = file_get_contents ( 'http://forums.devnetwork.net/viewtopic.php?t=50148' );
$regx = "|src\=\"?'?`?([[]:?=&@/._-]+)\"?'?`?|i";
preg_match_all ( $regx, $data, $src );
// strip array(0), don't need it
$src = $src[1];
print_r ( $src );
?>
Why is this forum stripping *
:alnum: * from the inner set of brackets
pif!
ryanrbftp
Forum Newbie
Posts: 8 Joined: Thu Jun 15, 2006 1:47 pm
Post
by ryanrbftp » Thu Jun 15, 2006 2:54 pm
Thank you for your reply.
This is my code:
Code: Select all
$data = $row['description'];
$regx = "|src\=\"?'?`?([[]:?=&@/._-]+)\"?'?`?|i";
preg_match_all ( $regx, $data, $src );
// strip array(0), don't need it
$src = $src[1];
echo "<g:image_link>$src</g:image_link>\n";
However, all thats getting returned is this:
<g:image_link>Array</g:image_link>
Any ideas?
printf
Forum Contributor
Posts: 173 Joined: Wed Jan 12, 2005 5:24 pm
Post
by printf » Thu Jun 15, 2006 3:26 pm
Because this forum is messing up the PHP REGEX, like it does for so many other things!
replace the other regex with this!
Code: Select all
$regx = "|src\=\"?'?`?([[:alnum:]:?=&@/._-]+)\"?'?`?|i";
pif!
ryanrbftp
Forum Newbie
Posts: 8 Joined: Thu Jun 15, 2006 1:47 pm
Post
by ryanrbftp » Thu Jun 15, 2006 3:35 pm
Still the same, just comes up with "Array". I'm entering :0123456789: and have also tried without the colons. Any ideas?
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Thu Jun 15, 2006 3:44 pm
printf wrote: Because this forum is messing up the PHP REGEX, like it does for so many other things!
It is not the forum, it is the GeSHi plugin for syntax highlighting. The problem has been reported and is being looked (reported for sure, looked at I think).
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Thu Jun 15, 2006 3:46 pm
ryanrbftp wrote: Still the same, just comes up with "Array". I'm entering :0123456789: and have also tried without the colons. Any ideas?
Do a print_r() of the array to see what is in it.
printf
Forum Contributor
Posts: 173 Joined: Wed Jan 12, 2005 5:24 pm
Post
by printf » Thu Jun 15, 2006 3:49 pm
Where are you putting this => :0123456789:, I hope not in the regex!
Code: Select all
<?
$data = file_get_contents ( 'http://forums.devnetwork.net/viewtopic.php?t=50148' );
$regx = "|src\=\"?'?`?([[:alnum:]:?=&@/._-]+)\"?'?`?|i";
preg_match_all ( $regx, $data, $src );
$src = $src[1];
print_r ( $src );
?>
pif!
ryanrbftp
Forum Newbie
Posts: 8 Joined: Thu Jun 15, 2006 1:47 pm
Post
by ryanrbftp » Thu Jun 15, 2006 3:55 pm
Code: Select all
$data = $row['description'];
$regx = "|src\=\"?'?`?([[:0123456789:]:?=&@/._-]+)\"?'?`?|i";
preg_match_all ( $regx, $data, $src );
$src = $src[1];
echo "<g:image_link>$src</g:image_link>\n";
ryanrbftp
Forum Newbie
Posts: 8 Joined: Thu Jun 15, 2006 1:47 pm
Post
by ryanrbftp » Thu Jun 15, 2006 3:59 pm
Sorry, I have changed my code to the following, but still nothing:
Code: Select all
$data = $row['description'];
$regx = "|src\=\"?'?`?([[:alnum:]:?=&@/._-]+)\"?'?`?|i";
preg_match_all ( $regx, $data, $src );
$src = $src[1];
echo "<g:image_link>$src</g:image_link>\n";
Printr of array shows:
Array
(
[0] => /images/aircraft/fs2002civiljets/737smokelarge.jpg
)
If I changed $src = $src[1]; to $src = $src[0], would that work?
ryanrbftp
Forum Newbie
Posts: 8 Joined: Thu Jun 15, 2006 1:47 pm
Post
by ryanrbftp » Thu Jun 15, 2006 4:03 pm
No, changing 1 to 0 didnt work either. It's because its printing only the first line of the output in my script. How can I get it to print only the
Code: Select all
/images/aircraft/fs2002civiljets/737smokelarge.jpg
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Thu Jun 15, 2006 4:03 pm
Try $src[1][0] and see what that does.
ryanrbftp
Forum Newbie
Posts: 8 Joined: Thu Jun 15, 2006 1:47 pm
Post
by ryanrbftp » Thu Jun 15, 2006 4:06 pm
no, $src = $src[0][1] didnt even print anything.
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Thu Jun 15, 2006 4:08 pm
Sorry, I edited the last post and my proxy server is slower than crud. Try $src[1][0].
Also,
the PHP Manual on preg_match_all has some pretty useful examples and how to capture what is the resulting array.