Results 1 to 6 of 6

Thread: [RESOLVED] preg_match

  1. #1

    Thread Starter
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Resolved [RESOLVED] preg_match

    I have never been good with regular expressions...

    PHP Code:
    function getTitle($Url){
        
    $str file_get_contents($Url);
        if(
    strlen($str)>0){
              
    $str preg_replace('/\s+/'' '$str);
            
    preg_match("/\<title\>(.+)\<\/title\>/i",$str,$title);
            if (isset(
    $title[1])) {
                if (
    $title[1]=='' ){
                    return 
    $Url;
                }else{
                    
                    return 
    trim($title[1]);
                }
            }else{
                return 
    $Url;
            }
                
        }


    works fine for any normal <title< </title> tags
    also works for titles with new lines...

    Im trying to get it to work with titles that have and id or something else

    so how do i tweak this:
    preg_match("/\<title\>(.+)\<\/title\>/i",$str,$title);
    to get this:
    <title id="pageTitle">THIS TITLE</title>

    tried:
    "/\<title.+\>(.+)\<\/title\>/i"
    "/\<title\.*\>(.+)\<\/title\>/i"
    "/\<title.*\>(.+)\<\/title\>/i"

    ??
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: preg_match

    I don't have a solution to your problem... but...

    Hi Static. You're not dead

  3. #3

    Thread Starter
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: preg_match

    lol Hey dclamp!!! .. nice avatar lol
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: preg_match

    I was trying to find the gangsta one you made for me several years ago. I found the link in a PM... but where ever it linked to was gone lol

  5. #5

    Thread Starter
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: preg_match

    lol those were cool looong gone now im sure.

    I found the answer!

    after using this:
    https://www.functions-online.com/preg_match.html

    to try over and over...

    PHP Code:
    preg_match("/<title.*>(.+)<\\/title>/i",$str,$title); 
    is the winner.. seems to work.
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  6. #6
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: [RESOLVED] preg_match

    Glad I could help.

Posting Permissions

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



Click Here to Expand Forum to Full Width