I
I
Islam Ibakaev2017-09-22 23:54:38
PHP
Islam Ibakaev, 2017-09-22 23:54:38

How to get a substring in php or smarty?

How from this line

"<div><p><img src="http://kolhoz1.mosco-web.ru/wa-data/public/blog/img/blog-image-4.png"></p><p>Какой-то текст</p></div>"

get a substring?
"<img src="http://kolhoz1.mosco-web.ru/wa-data/public/blog/img/blog-image-4.png">"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2017-09-23
@slo_nik

Goodnight.
Try starting with this regular expression.

A
Alexander, 2017-09-23
@zkelo

1 step. Get the part you want with regexp.

$re = '/(<img\ssrc=".*">)/';
$str = '<div><p><img src="http://kolhoz1.mosco-web.ru/wa-data/public/blog/img/blog-image-4.png"></p><p>Какой-то текст</p></div>';

preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);

// Print the entire match result
var_dump($matches);

Link
2 step. Passing to the template:Smarty->assign(...)->display(...);
Берёте код из 1 шага и помещаете в {php}{/php}, и в этих же тегах {php}
выполняете Smarty->assign(...);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question