最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - preg_replace specific Text to small latter strtolower

programmeradmin0浏览0评论
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 4 years ago.

Improve this question

Please i need to replace link with capital letter to small letter using wp function E.g let every text after /get/ be replace with small letter.

<a href=""> => <a href="">
<a href=""> => <a href="">

here is my function, I dont know where i am getting it wrong. however i am not good in wp. please correct me by posting the full correct code.

function emailleftappend($content){

        $findleft = '/get\/(?<=\/)([A-Za-z]+?) ([A-Za-z]+?)(?=\/">)/m';
        $replaceleft = '$1-$2';
        $content = preg_replace(strtolower($findleft), $replaceleft, $content);

    return $content;
}
add_filter('the_content', 'emailleftappend');
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 4 years ago.

Improve this question

Please i need to replace link with capital letter to small letter using wp function E.g let every text after /get/ be replace with small letter.

<a href="https://stackexchange/get/ASK-Question"> => <a href="https://stackexchange/get/ask-question">
<a href="https://stackexchange/get/aSK-QuesTion"> => <a href="https://stackexchange/get/ask-question">

here is my function, I dont know where i am getting it wrong. however i am not good in wp. please correct me by posting the full correct code.

function emailleftappend($content){

        $findleft = '/get\/(?<=\/)([A-Za-z]+?) ([A-Za-z]+?)(?=\/">)/m';
        $replaceleft = '$1-$2';
        $content = preg_replace(strtolower($findleft), $replaceleft, $content);

    return $content;
}
add_filter('the_content', 'emailleftappend');
Share Improve this question asked May 26, 2020 at 22:37 XATAXATA 6712 bronze badges 2
  • This is your fourth version of this question in half as many days. If you have something to add, please edit the original question. – Jacob Peattie Commented May 27, 2020 at 3:33
  • please kindly help me out if you know how to fix this please. – XATA Commented May 27, 2020 at 3:55
Add a comment  | 

1 Answer 1

Reset to default 1
function emailleftappend($content){


    $content = preg_replace_callback('/(?<=get\/)(.*?)-(.*?)(?=\/">)/', function ($m) {
  return sanitize_title($m[1]). '-'. sanitize_title($m[2]); }, $content);

    return $content;
}
add_filter('the_content', 'emailleftappend');

the above fixed the issue for me. another way is below.

function emailleftappend($content){

        $content = preg_replace_callback('/(?<=get\/)(.*?)-(.*?)(?=\/">)/', function ($m) {
      return slug($m[1]). '-'. slug($m[2]); }, $content);

        return $content;
    }
    add_filter('the_content', 'emailleftappend');

function slug($z){
    $z = strtolower($z);
    $z = preg_replace('/[^a-z0-9 -]+/', '', $z);
    $z = str_replace(' ', '-', $z);
    return trim($z, '-');
}

FINALLY FIXED

发布评论

评论列表(0)

  1. 暂无评论