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 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Simple Regex Help

    Hi,

    I cam accross this regex pattern:

    PHP Code:
    <TAGb[^>]*>(.*?)</TAG
    I want to grab titles from websites, so I edited to get:

    PHP Code:
    <titleb[^>]*>(.*?)</title
    Could anyone please explain why it doesn't work?

    Thanks.

    (Note: The forum won't let me put backslashes, there should be one before the "b")
    Last edited by BRUm; 08-28-2006 at 09:54 AM.

  • #2
    New Coder
    Join Date
    Aug 2006
    Posts
    34
    Thanks
    0
    Thanked 1 Time in 1 Post
    What you're looking for is this:
    PHP Code:
    $pattern '<title>(.+)</title>'
    Might want to make sure that you set preg_match (or whatever you're using) to being case-insensitive.

  • #3
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hm I just tried that, and I still only get
    PHP Code:
    Array ( ) 

  • #4
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    the pattern should have delimiters, i.e:
    PHP Code:
    $pattern='#<title>(.+)</title>#'
    And this pattern won't let the <title> have any attributes, for example:
    <title id="theid">
    won't match, is that an issue?
    showing your code is always helpful...

  • #5
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Title has attributes? I just need to match the basic HTML <title> tag.

    Example:

    Code:
    <title>This is my website</title>
    The pattern should return (When array is printed):

    Code:
    This is my website
    But it doesn't.

  • #6
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,797
    Thanks
    19
    Thanked 156 Times in 147 Posts
    Like GJay said, for the most part:

    PHP Code:
    $page_content file_get_contents('MyPage.php');
    $pattern '/(<title>)(.+?)(<\/title>)/i';
    preg_match($pattern,$page_content,$matches);

    echo 
    "The title tag content is: ".$matches[2]; 
    Last edited by chump2877; 08-28-2006 at 02:32 PM.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #7
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi chump,

    Thanks for your help, but I tried your code by itself and I get an error on your preg_match line. You missed off a ; but I still get the error after I corrected it. :S

  • #8
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,797
    Thanks
    19
    Thanked 156 Times in 147 Posts
    Quote Originally Posted by BRUm
    Hi chump,

    Thanks for your help, but I tried your code by itself and I get an error on your preg_match line. You missed off a ; but I still get the error after I corrected it. :S
    Sorry about the semi-colon...I added that in, and it works fine now for me...what error are you getting?
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #9
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ah, it seems I had saved the script to my C:\ whereas I was uploaded the old script thinking I had updated it lol the script works, thank you


  •  

    Posting Permissions

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