Created
December 14, 2017 08:02
-
-
Save mokoshalb/2815a89586612c3533704447bbfd33af to your computer and use it in GitHub Desktop.
How to PHP regex match an HTML document's title
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function parseTitle($html) { | |
// Get the text in a <title> | |
$matches = array(); | |
preg_match("/<title>(.*)<\/title>/is", $html, $matches); | |
if (count($matches) > 1) { | |
return trim($matches[1]); | |
} else { | |
return null; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment