-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
  • 33,525
  • 7
  • 51
  • 64
  • 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,244
  • 2
  • 8
  • 15
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,891
  • 5
  • 33
  • 68