Jump to content

preg_match_all


phorcon3

Recommended Posts

here's the string

 

<a href="/online/frame.htm?si=2m70n.1jpqGQ.1rgs6v.C**&v=1">

 

and i have to find

 

/online/frame.htm?si=2m70n.1jpqGQ.1rgs6v.C**&v=1

 

and i tried using:

 

<?php

$html = '<a href="/online/frame.htm?si=2m70n.1jpqGQ.1rgs6v.C**&v=1">';

preg_match_all('/href="/online/frame.htm?si=(.*?)&v=1"/', $html, $match);

$find = $match[1][0];

echo $find;

?>

 

but it just wouldn't output anything. any ideas to why that is?

 

<?php

preg_match_all('/frame.htm?si=(.*?)&v=1/', $result, $matches);

?>

 

doesn't work either.

Link to comment
Share on other sites

that's cuz ya using the delimeters within the patters

 

/ # set start/end delimeter

href="/online/frame.htm?si=(.*?)&v=1" # our search pattern

/ # end delimeter

 

so it will just look for href="

and think everything beyond that is a optional preg parameter (not a pattern)

 

easiest way change the delimeter

@href="/online/frame.htm?si=(.*?)&v=1"@

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.