简体   繁体   中英

How do I replace a link between <a></a> and keep the link from href unchanged?

How do I replace a link between and keep the link from href unchanged?

This is my code:

$str="Lorem Ipsum.<a href='https://test.be/assets/kcfinder/upload/files/certificat_auto.pdf'>https://test.be/assets/kcfinder/upload/files/certificat_auto.pdf</a>Lorem Ipsum ";

$pattern = '/>https:\/\/test.be\/assets\/kcfinder\/upload\/files\/.*\./';
$replacement = '>${1}';

echo preg_replace($pattern, $replacement, $str);

This is the output:

Lorem Ipsum.<a href='https://test.be/assets/kcfinder/upload/files/certificat_auto.pdf'>pdf</a>Lorem Ipsum 

I need the output to be :

Lorem Ipsum.<a href='https://test.be/assets/kcfinder/upload/files/certificat_auto.pdf'>certificat_auto.pdf</a>Lorem Ipsum 

I'm doing something wrong with the replacement, the pattern matches

You may get some idea from this.

(?<=>)https:\/\/test.be\/assets\/kcfinder\/upload\/files\/[\w\.]*

https://rubular.com/r/b46dQ9G27C4A3A

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM