Jeff VIP
Total posts: 745
05 Нояб 2013 18:38

Hi,

I would like to print/echo the url of the (thumbnail) image without the markup.

I have tried

echo $item->fields_by_id[12]->result;

Which returns the image with full html markup

echo strip_tags($item->fields_by_id[12]->result);

Which returns nothing ?

I can't figure out how to do this with the thumbnail.

Best regards,

Jeff

Последние изменения: 02 Март 2014


Sergey
Total posts: 13,748
06 Нояб 2013 01:03

preg_match("/src=\"([^\"]*)/", $item->fields_by_id[12]->result, $match);

echo $match[1];


Jeff VIP
Total posts: 745
06 Нояб 2013 02:38

I get this warning:

Warning: preg_match() [function.preg-match]: Compilation failed: missing terminating ] for character class at offset 12 in /home/mysite/public_html/components/com_cobalt/views/record/tmpl/default_record_custom_article.php on line 112

Adding terminating bracket into the code

preg_match("/src=\"([^\">*])/", $item->fields_by_id[12]->result, $match);

echo $match[1]; 

Produces no warning, but the output of $match[1] is

/

:(


Jeff VIP
Total posts: 745
06 Нояб 2013 04:57

I found a solution that actually works without using preg_match :D

$dom = new DOMDocument;

$dom->loadHTML($item->fields_by_id[12]->result);

$x = new DOMXPath($dom); 

foreach($x->query("//img") as $node) 

{

    echo $node->getAttribute("src");

}

Sergey
Total posts: 13,748
06 Нояб 2013 05:52

Работает на Cobalt