-2

I have the following string:

$string = java-developer-jobs

I would like to remove - and jobs from $string, but I don't want to use str_replace multiple times.

Oldskool
  • 34,211
  • 7
  • 53
  • 66
  • 3
    actually you don't need to invoke `str_replace` multiple times in each individual characters. it can hold multiple replacements also, just use an array, its in the [manual](http://php.net/manual/en/function.str-replace.php) – Kevin Nov 30 '16 at 06:21

2 Answers2

0

Use array as :

$toReplace = array('-','jobs');
$with = array('','');
$string = 'java-developer-jobs';

str_replace($toReplace,$with,$string);
Rahul
  • 2,374
  • 2
  • 9
  • 17
0

You can use regex for this.Try something like this:

$string = "java-developer-jobs";
$sentence = preg_replace('/\-|jobs/', ' ', $string);
echo $sentence;

Output: java developer

LIVE DEMO

Chonchol Mahmud
  • 2,717
  • 7
  • 39
  • 72