echo a variable inside a php string replace

后端 未结 3 908
忘掉有多难
忘掉有多难 2021-01-23 17:42

I currently trying to do a str_replace in PHP which is new to me. Here is my current code.

$postAddress = str_replace(\"/current-url/\", \"/path/to/my-news/post/         


        
相关标签:
3条回答
  • 2021-01-23 18:17

    have a look at PHP String Operators.

    $postAddress = str_replace("/current-url/", "/path/to/" . $cat->getTitle() . "/post/", $postAddress);
    
    0 讨论(0)
  • 2021-01-23 18:20

    I think You have to do this:

    $postAddress = str_replace("/current-url/", "/path/to/".$cat->getTitle()."/post/", $postAddress);
    
    0 讨论(0)
  • 2021-01-23 18:23
    $postAddress = str_replace("/current-url/", "/path/to/" . $cat->getTitle() . "/post/", $postAddress);
    

    Is that what you want? Use . for concatenation and don't echo the variable.

    0 讨论(0)
提交回复
热议问题