Jump to content

Recommended Posts

Hi all, I can never get my head around regex

 

I have a string (Never would have guessed that bit for regex help would you)

The string is the Content of a website.

 

I want to try and find the following

 

1) What does it say under the meta tag

<meta name="description" content="THIS BIT HERE BUT IT MIGHT BE NULL" />

2) if the following exists and what the content is

<meta name="revisit-after" content="5" />

 

3) if an iframe is found and the source.

 

This is a bit complex as meta could be META or MeTa (so I want case insensitive)

They could use Single Quote or Double Quote

 

The best method, if possible (I know its possible, if you guys could help)

Get an array all all the meta tags on the website

Split the name and Description

 

Thus allowing me to check multiple things.

 

Praise you lot, my head hurts just thinking about it

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/191044-regex-checks-preg_match/
Share on other sites

You should be able to use get_meta_tags() for the META tags (else the comments on that page also contains regex solutions).

 

You can check for iframes with this:

 

//$html contains page source code
if (preg_match_all('~<iframe\b[^>]+src\s?=\s?([\'"])(.+?)\1[^>]*>~is', $html, $matches)) {
echo '<pre>' . print_r($matches[2], true) . '</pre>';
} else {
echo 'No iframes found.';
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.