Jump to content

Replace A Character


MarkT

Recommended Posts

Hello,

I have a PHP echo from my db, $request2['content'], which I want to replace any ' characters with this; '

 

Can anyone provide me the code please to add to the page.

Link to comment
Share on other sites

I've just tried;

$request = mysqli_query($con,"SELECT * from match_reports WHERE id='{$_GET['id']}'");$request2 = mysqli_fetch_array($request);$correct2 = str_replace("'", "'",$request2['content']);

But it's not replacing it?

Link to comment
Share on other sites

$request1 = "It jess ain't my copyright problem.";$len1 = strlen($request1);$correct1 = str_replace("'", "©", $request1);$len2 = strlen($correct1);echo "{$request1} {$len1} <br/>{$correct1} {$len2}";
Edited by davej
Link to comment
Share on other sites

$request1 = "It jess ain't my copyright problem.";$len1 = strlen($request1);$correct1 = str_replace("'", "©", $request1);$len2 = strlen($correct1);echo "{$request1} {$len1} <br/>{$correct1} {$len2}";

$correct1 = str_replace("'", "'", $request2['content']);

 

Still not working mate. Here's whats wrong; http://dittonminorsfc.co.uk/matchreports.php?id=6

 

It shows up with ?, it shows the ' when you use ' but it doesn't like ' straight into text.

 

Any ideas?

Link to comment
Share on other sites

I'll fix those after, but what I'm focusing on is the problem in the original question. Any ideas how to fix it?

Link to comment
Share on other sites

You are targeting apostrophes, those characters are right and left single quotes ’ ‘ (characters dont show up here), this usually results from copying and pasting from MS word, these characters are causing the problem.

So you're saying they should be typed in>?

Link to comment
Share on other sites

No, you just have to careful in future and not use single left/right characters, or when this text IS uploaded to database replace with character codes instead, that will prevent this kind of problem.

 

OR

$filter_bad = str_replace(chr(145),"'", $request2['content']);//left quote$filter_bad = str_replace(chr(146),"'", $filter_bad); //right quote$filter_good = $filter_bad = str_replace("'","'", $filter_bad); //apostropheecho $filter_good;
Edited by dsonesuk
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...