-1

sorry for not beeing able to put the title exactly what my question, I can't find a way to ask it.

So im trying to replace all ' in a text inside and replace it for ' in php

I have a variable $desc = "he's such a good person and he'll be very successfull";

and I'm trying to do the following

$desc = str_replace("'","'",$desc);

But no success is there a way to use regex in str_replace?

Yes it looks to be fine now... for some reason.

Is there a way to use regex for it?

for example to remove html tags from the text?

$desc = "<strong> he&#39;s such a good person </strong> <br /> he&#39;ll be very successfull";

$desc = str_replace("<*>"," ",$desc);

Juanfri Lira
  • 423
  • 3
  • 7
  • 17

3 Answers3

2

You may try to use the correct PHP function to do this job, so please take a look at : preg_replace doc.

In your case, you would like to use like this :

preg_replace('/&#39;/', "'", $desc);

Take a look at this execution: https://eval.in/800948

Sense
  • 1,096
  • 8
  • 20
0

Does it have to be a regex because this is a lot simpler way to do it

$desc = "he&#39;s such a good person and he&#39;ll be very successfull";

$new = str_replace('&#39;', "'", $desc);
echo $new;

RESULT:

he's such a good person and he'll be very successfull
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
0

You don't need to use regex as it will be more complex use

$desc = "he&#39;s such a good person and he&#39;ll be very       successfull";
$desc = str_replace("&#39;","'",$desc);
echo "after replace :"." ".$desc;    

it is more simpler :)