Extracting content from meta tag PHP MYHTML DOM

weekapaug
weekapaug used Ask the Experts™
on
There is a meta tag I need to isolate and extract data from and it looks like this.  The selector description has a colon in it and I'm not sure if this an issue or its just my syntax.  I tried to get around it with a wildcard search but it did nothing either.

<meta name="somefield:withColons" content="I need whats here in plain text">

Open in new window


I have tried a few things that I'm showing below but can not get the value to show up.  I get no errors either on some, just nothing but I know its there...

NOTHING BELOW HERE WORKS FOR ME
$myVar=$html->find("meta[name='somefield:withColons']")->content;
$myVar=$html->find(meta[name*=somefield)->content;
$myVar=$html->find("meta[name='somefield:withColons']")->plaintext;
$myVar=$html->find(meta[name*=somefield)->plaintextt;

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016
Commented:
Please see: https://iconoun.com/demo/temp_weekapaug.php
<?php // demo/temp_weekapaug.php
/**
 * https://www.experts-exchange.com/questions/29008038/Extracting-content-from-meta-tag-PHP-MYHTML-DOM.html
 *
 * http://simplehtmldom.sourceforge.net/
 */
error_reporting(E_ALL);
echo '<pre>';

// LOAD THE DOM PARSER
require_once('simplehtmldom_1_5/simple_html_dom.php');

// THE TEST DATA FROM THE POST AT E-E
$htm = <<<EOD
<meta name="somefield:withColons" content="I need whats here in plain text">
EOD;

// GET THE HTML INTO A DOM OBJECT
$dom = str_get_html($htm);

// USE ITERATORS TO FIND THE DATA
foreach ($dom->find('meta[name=somefield:withColons]') as $meta_element)
{
    var_dump($meta_element->attr['content']);
}

Open in new window

Outputs:
string(31) "I need whats here in plain text"

Open in new window

Author

Commented:
You did it again Ray!! Thank you it was the line below that I was stuck on.  didnt know about the attr tag!

($meta_element->attr['content'])
Most Valuable Expert 2011
Top Expert 2016

Commented:
Glad to help!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial