Q:

PHP convert  tag to amp img

I have some text field in MySQL table that contains some HTML and image (as html tag) 
I need to output the same content inside an AMP page but amp omg tag is different, how can i convert my tag to amp tag?
should i search my variable for image tag?

A:

Something as simple as this should work:
            <?php
                    $string = 'some string containing evil <img src="abc.gif"> tags here and also here: <img src="xyz.png">';
                    $pattern = '/<img/i';
                    $replacement = '<amp-img';
                    preg_replace($pattern, $replacement, $string);
            ?>

Without seeing the actual code it's hard to see exactly what you need to do, but these links should point you in the right direction for getting stuck into regular expressions, which you are clearly going to need if, as you say in the comments below, you need to break up the old img tags into component parts and refactor them in various ways. 
PHP regex groups captures
http://www.regular-expressions.info/tutorial.html
Don't be tempted to use substrings as an easy way out, regular expressions are well worth the time invested.

