MarkT Posted February 21, 2014 Share Posted February 21, 2014 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 More sharing options...
davej Posted February 21, 2014 Share Posted February 21, 2014 (edited) Have you tried... Php: http://us3.php.net/str_replace or Javascript: http://www.w3schools.com/jsref/jsref_replace.asp Edited February 21, 2014 by davej Link to comment Share on other sites More sharing options...
MarkT Posted February 22, 2014 Author Share Posted February 22, 2014 Have you tried... Php: http://us3.php.net/str_replace or Javascript: http://www.w3schools.com/jsref/jsref_replace.asp I've tried the javascript, but didn't really get what I should do with it. Can you explain it in lame terms please. Link to comment Share on other sites More sharing options...
MarkT Posted February 22, 2014 Author Share Posted February 22, 2014 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 More sharing options...
davej Posted February 22, 2014 Share Posted February 22, 2014 (edited) $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 February 22, 2014 by davej Link to comment Share on other sites More sharing options...
MarkT Posted February 22, 2014 Author Share Posted February 22, 2014 $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 More sharing options...
dsonesuk Posted February 22, 2014 Share Posted February 22, 2014 Just to be sure... you are looking at the view source when you tested it, not the result through looking at it through a browser. cause #4 should work. Link to comment Share on other sites More sharing options...
dsonesuk Posted February 22, 2014 Share Posted February 22, 2014 that is more like a character set problem maybe from database setting. Link to comment Share on other sites More sharing options...
MarkT Posted February 22, 2014 Author Share Posted February 22, 2014 Other match reports there, when I corrected them and put ', instead of the ' it works. Should I be looking at the input page? Link to comment Share on other sites More sharing options...
davej Posted February 22, 2014 Share Posted February 22, 2014 I noticed your html tag is missing but the W3C Validator lists 45 errors... http://validator.w3.org/check?uri=http%3A%2F%2Fdittonminorsfc.co.uk&charset=%28detect+automatically%29&doctype=Inline&group=0 Link to comment Share on other sites More sharing options...
MarkT Posted February 22, 2014 Author Share Posted February 22, 2014 I noticed your html tag is missing but the W3C Validator lists 45 errors... http://validator.w3.org/check?uri=http%3A%2F%2Fdittonminorsfc.co.uk&charset=%28detect+automatically%29&doctype=Inline&group=0 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 More sharing options...
dsonesuk Posted February 22, 2014 Share Posted February 22, 2014 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. Link to comment Share on other sites More sharing options...
MarkT Posted February 22, 2014 Author Share Posted February 22, 2014 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 More sharing options...
dsonesuk Posted February 22, 2014 Share Posted February 22, 2014 (edited) 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 February 22, 2014 by dsonesuk Link to comment Share on other sites More sharing options...
davej Posted February 22, 2014 Share Posted February 22, 2014 Add an html tag. http://www.w3schools.com/tags/tag_html.asp Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now