I want to extract contents of title tag from html string. I have done some search but so far i am not able to find such code in VB/C# or PHP. Also this should work with both upper and lower case tags e.g. should work with both <title></title>
and <TITLE></TITLE>
. Thank you.
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
- Extract P-Values from Dunnett Test into a Table by
Sounds like a job for a regular expression. This will depend on the HTML being well-formed, i.e., only finds the title element inside a head element.
I don't have my regex cheat sheet in front of me so it may need a little tweaking. Note that there is also no error checking in the case where no title element exists.
You can use regular expressions for this but it's not completely error-proof. It'll do if you just want something simple though (in PHP):
If there is any attribute in the title tag (which is unlikely but can happen) you need to update the expression as follows: