Home > Backend Development > PHP Tutorial > str_replace的很简单的一个有关问题.多谢了.

str_replace的很简单的一个有关问题.多谢了.

WBOY
Release: 2016-06-13 13:43:17
Original
1011 people have browsed it

str_replace的很简单的一个问题.谢谢了...
比如
$a="123a456a78a9a"
将上面的a替换为b;但是只替换最后一个a...
如果没有什么好办法的话...可以确定在最后一个a之前的位数是12位的.....然后也就是只替换第13位置这个a;
谢谢了.

------解决方案--------------------

PHP code

echo strrev(preg_replace('/a/','b',strrev($a),1));
<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
PHP code
echo preg_replace('/a[^a]*$/','b',$a);
<br><font color="#e78608">------解决方案--------------------</font><br>上面写错了<br>
Copy after login
PHP code
echo preg_replace('/a([^a]*)$/','b$1',$a); <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template