Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts

    what does this mean (.*)

    I came across this line in a code that i have and i dont know what it means

    PHP Code:
    $strContent file_get_contents($strListingUrl);

    $strListMatches '!<a class="details" href="(.*)" title="(.*)">(.*)</a>!isU';
                
    $objListMatches getMatches($strListMatches,$strContent); 
    can anyone explain it in simple english for me please

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    That string is a regular expression. The .* means match any character 0 or more times.
    OracleGuy

  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts
    so does this code mean that it gets everything in a page and sets it as a variable $strContent and then takes everything out that matches

    PHP Code:
    '!<a class="details" href="(.*)" title="(.*)">(.*)</a>!isU' 
    and puts them into $objListMatches

    Yes?

    is $objListMatches now an array?????

    Thanks for your help

  • #4
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    Quote Originally Posted by kevinkhan View Post
    I came across this line in a code that i have and i dont know what it means

    PHP Code:
    $strContent file_get_contents($strListingUrl);

    $strListMatches '!<a class="details" href="(.*)" title="(.*)">(.*)</a>!isU';
                
    $objListMatches getMatches($strListMatches,$strContent); 
    can anyone explain it in simple english for me please
    Yeah, what oracleguy said, except... It doesn't work...

    PHP Code:
    $strListMatches '!<a class="details" href="(.*?)" title="(.*?)">(.*?)</a>!isU'
    Or...

    PHP Code:
    $strListMatches '!<a class="details" href="([^"]*)" title="([^"]*)">(.*?)</a>!isU'
    Why doesn't it work, I hear you cry?!

    <a class="details" href="a" title="b">c</a><a class="details" href="d" title="e">f</a>

    Will match the first:
    href="a"
    as
    href="a" title="b">c</a><a class="details" href="d
    Because .* also matches the closing "
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • #5
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Quote Originally Posted by kevinkhan View Post
    so does this code mean that it gets everything in a page and sets it as a variable $strContent and then takes everything out that matches

    PHP Code:
    '!<a class="details" href="(.*)" title="(.*)">(.*)</a>!isU' 
    and puts them into $objListMatches

    Yes?

    is $objListMatches now an array?????

    Thanks for your help
    getMatches isn't a standard PHP function, it must be a user created one so I can't say what it is doing without seeing the implementation.

    Quote Originally Posted by ComputerX View Post
    Yeah, what oracleguy said, except... It doesn't work...

    PHP Code:
    $strListMatches '!<a class="details" href="(.*?)" title="(.*?)">(.*?)</a>!isU'
    Or...

    PHP Code:
    $strListMatches '!<a class="details" href="([^"]*)" title="([^"]*)">(.*?)</a>!isU'
    Why doesn't it work, I hear you cry?!

    <a class="details" href="a" title="b">c</a><a class="details" href="d" title="e">f</a>

    Will match the first:
    href="a"
    as
    href="a" title="b">c</a><a class="details" href="d
    Because .* also matches the closing "
    Yep you're right; using the period character like that is a common mistake made by people inexperienced with regular expressions.
    OracleGuy

  • #6
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for sharing your codes...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •