-
Sep 10th, 2014, 04:55 PM
#1
[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"
-
Sep 10th, 2014, 07:42 PM
#2
Re: preg_match
I don't have a solution to your problem... but...
Hi Static. You're not dead
-
Sep 10th, 2014, 09:25 PM
#3
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"
-
Sep 10th, 2014, 09:53 PM
#4
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
-
Sep 11th, 2014, 07:55 AM
#5
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"
-
Sep 11th, 2014, 01:38 PM
#6
Re: [RESOLVED] preg_match
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|