how to replace a string contains space with -

前端 未结 2 1848
栀梦
栀梦 2021-01-29 03:30
$url_name = str_replace(\" \",\"-\",$entry[\'department_name\']);
$url_name = str_replace(\" & \",\"-amp-\",$entry[\'department_name\']);

Hi iam re

相关标签:
2条回答
  • 2021-01-29 04:21

    Is this what you want? Note I'm using str_replace here with the search/replace args as arrays to save you doing multiple calls to str_replace()

    $search = array(' & ', ' ');
    $replace = array('-amp-', '-');
    $url_name = str_replace($search, $replace, $entry['department_name']);
    
    0 讨论(0)
  • 2021-01-29 04:32

    Put the amp replacement first.

    $url_name = str_replace(" & ","-amp-",$entry['department_name']);
    $url_name = str_replace(" ","-",$url_name);
    
    0 讨论(0)
提交回复
热议问题