Extracting content from meta tag PHP MYHTML DOM

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

weekapaugAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
weekapaugAuthor 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'])
0
Ray PaseurCommented:
Glad to help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.