Rich text data in my database is the type of formatted articles that contain html tags, now I want to traverse the data in this rich text and add hyperlinks to all the img, and then set the connection address of the hyperlink to the img Image address directly, the hyperlink contains a pair... rich text data in my database is the type of formatted articles that contain html tags, now I want to traverse the data in this rich text and add hyperlinks to all the img, and then set the connection address of the hyperlink to the img Image address directly, you must set the corresponding class style in the hyperlink. Is there a good alternative?
Reply content:
Rich text data in my database is the type of formatted articles that contain html tags, now I want to traverse the data in this rich text and add hyperlinks to all the img, and then set the connection address of the hyperlink to the img Image address directly, you must set the corresponding class style in the hyperlink. Is there a good alternative?
You can use regular expressions.preg_replace()
Function. Replace as follows
// $ Desc your rich text data $ replace = preg_replace ('/<\ s * img \ s + [^>] *? Src \ s * = \ s * ('| \")(.*?) \ 1 [^>] *? \/? \ S *>/I ',' $ 0', $ desc );
You can usephp
Ofpreg_replace()
Replace functions with regular expressions.
In addition to LS expressions. If you only want users to jump to view the large Image/source image when clicking the image, why not use js? You can do this with simple code without having to do it on the server:
$('body').on('click', 'img', function(){ location.href = $(this).attr('src');});