Home > Backend Development > PHP Tutorial > How to use regular php to copy src and put it into another attribute of this tag

How to use regular php to copy src and put it into another attribute of this tag

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-06 13:53:19
Original
952 people have browsed it

has characters

xxxx<img src=“a.jpg”>xxxx<img src=“b.jpg”>.......

If there are many words like this add img tag

How to use regular expressions to change all img tags into

xxxx<img src=“a.jpg” data-url="a.jpg">xxxx<img src=“b.jpg” data-url="b.jpg">.......

has one more data-url, and its value is equal to src

Reply content:

has characters

xxxx<img src=“a.jpg”>xxxx<img src=“b.jpg”>.......

If there are many words like this add img tag

How to use regular expressions to change all img tags into

xxxx<img src=“a.jpg” data-url="a.jpg">xxxx<img src=“b.jpg” data-url="b.jpg">.......

has one more data-url, and its value is equal to src

If it is the same attribute value, then can you just get the src attribute directly when getting it? I don’t understand what your needs are

But if you must use PHP regular implementation, you can also use the preg_replace_callback method to replace it. Use regular rules to match src="a.jpg" and replace it with src="a.jpg" data-url=" a.jpg" will do

Can I use jq? The following is the jq method

1

2

3

4

5

6

7

8

9

10

11

<code><img  src="1242x225.jpg" />

<script type="text/javascript">

 $("img").each(function(i){

    var img_url = $('img')[i].src;

    var img_name = img_url.substring(img_url.lastIndexOf("/")+1,img_url.length);

    $(this).attr("data-url",img_name);

});

</script>

以下是浏览器打印效果

 

</code>

Copy after login

How to use regular php to copy src and put it into another attribute of this tag

Related labels:
php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template