When processing opencart image loading, I want to use the lazylaod jquery plug-in.
The frontend of the website is displayed, but when loading in the background, I found 2, and the images of the edited products in the background are not displayed.
Because I use the crawler to automatically fill in the products, without adding them manually in the background. That is to say, when processing lazyload to display images, the src data-data-original width height attributes are generated all at once, so the background display cannot be seen, but the review element can be seen.
PHP is added like this, and it can be reproduced as follows:
<code>foreach (xx as x){ $imgs.='<img src="image/catalog/lazyload_grey.gif" data-original='.$tmp.'image/catalog/product/'.$id."/".$value.' width="800" height='800'>'; } </code>
At that time, I thought that it would be better to replace the regular expression in the background controller. I tried it and it worked. But it will be overwritten when the product is updated.
Think about it, it’s better to process it through the front desk, using js or ob function.
Although I have not dealt with either of these two, I still record my ideas and wait until the website really needs optimization before taking concrete actions.
The following is a small example of the ob function:
<code><?php ob_start(); echo '13712345678'; echo 'another content<br>'; $result=ob_get_contents(); echo '<hr>'; ob_clean(); if(preg_match('/\d{11,}/', $result,$match)){ echo str_replace(substr($match[0],-4),'****',$match[0]); }else{ echo 'no match'; } ob_end_flush(); // result:1371234**** </code>
I have not dealt with it, and I feel that both methods are not very good. I hope you can provide some more methods or ideas to deal with the problem that the front and backend cannot be displayed consistently when lazyloading or similar lazy loading of images occurs.
Reference website:
ob function handles lazyload
lazyload
The above introduces the small usage of obstart, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.