Solarpitch Posted July 4, 2008 Share Posted July 4, 2008 Whats up guys, Here.. This is right isnt it? I'm basically trying to see if the sting has a " ' " in it and replace it with noting but doesnt seem to be working. Just wanted to run the syntax bu you. <?php $p = str_replace("'", "", $player); ?> Link to comment https://forums.phpfreaks.com/topic/113239-solved-str-replace-question/ Share on other sites More sharing options...
teynon Posted July 4, 2008 Share Posted July 4, 2008 Try using this: $p = str_replace("\'", "", $player); If not, its fine, just make sure your not confusing yourself somewhere else. Link to comment https://forums.phpfreaks.com/topic/113239-solved-str-replace-question/#findComment-581743 Share on other sites More sharing options...
Solarpitch Posted July 4, 2008 Author Share Posted July 4, 2008 No, I must be confusing myself somewhere. I'll have another look through the code and see whats going on. Cheers Link to comment https://forums.phpfreaks.com/topic/113239-solved-str-replace-question/#findComment-581749 Share on other sites More sharing options...
kenrbnsn Posted July 4, 2008 Share Posted July 4, 2008 The OP's code should work. How do you know it's not working? Try this: <?php $player = "This string has single quotes (' ' ' ' ') in it"; $p = str_replace("'", "", $player); echo 'Original string: ' . htmlentities($player,ENT_QUOTES) . "<br>\n"; echo 'New string: ' . htmlentities($p, ENT_QUOTES); ?> Ken Link to comment https://forums.phpfreaks.com/topic/113239-solved-str-replace-question/#findComment-581751 Share on other sites More sharing options...
Solarpitch Posted July 4, 2008 Author Share Posted July 4, 2008 The reason I need to replace the " ' " is because the result will not show up in a pop up if it has this character. So if a players name is John O' Reilly, he wont display in the popup. Here I'm getting the persons name from the database, I just check to see if its a numeric value and if it is it goes to a different function to get there name. Then once I have the value in $player, if its John O' Reilly I want to replace the " ' " with noting so that it will show up when the mouse rolls over this javascript popup I have <?php $p1 = $row[3]; if(is_numeric($p1)){$player1 = get_name2($p1, "member");}else{$player1 = $p1;} if($p1 == ""){$player1 = "Available";} $p2 = $row[5]; if(is_numeric($p2)){$player2 = get_name2($p2, "member");}else{$player2 = $p2;} if($p2 == ""){$player2 = "Available";} $p3 = $row[7]; if(is_numeric($p3)){$player3 = get_name2($p3, "member");}else{$player3 = $p3;} if($p3 == ""){$player3 = "Available";} $p4 = $row[9]; if(is_numeric($p4)){$player4 = get_name2($p4, "member");}else{$player4 = $p4;} if($p4 == ""){$player4 = "Available";} $player1 = str_replace("'", "", $player1); $player2 = str_replace("'", "", $player2); $player3 = str_replace("'", "", $player3); $player4 = str_replace("'", "", $player4); ?> Link to comment https://forums.phpfreaks.com/topic/113239-solved-str-replace-question/#findComment-581757 Share on other sites More sharing options...
DarkWater Posted July 4, 2008 Share Posted July 4, 2008 Just use htmlentities($var, ENT_QUOTES); Link to comment https://forums.phpfreaks.com/topic/113239-solved-str-replace-question/#findComment-581759 Share on other sites More sharing options...
Solarpitch Posted July 4, 2008 Author Share Posted July 4, 2008 That doesnt work either Dark Water. Link to comment https://forums.phpfreaks.com/topic/113239-solved-str-replace-question/#findComment-581761 Share on other sites More sharing options...
Solarpitch Posted July 4, 2008 Author Share Posted July 4, 2008 Actually... There might be a chance I'm uploading the wrong file to the server, if I am... I'll personally ban myself from the site! :-\ Link to comment https://forums.phpfreaks.com/topic/113239-solved-str-replace-question/#findComment-581764 Share on other sites More sharing options...
br0ken Posted July 4, 2008 Share Posted July 4, 2008 What data is actually in $player? If you could show us that it might help. Also, try running stripslashes() on $player before passing it to str_replace(). It's a long shot but it might just work! Link to comment https://forums.phpfreaks.com/topic/113239-solved-str-replace-question/#findComment-581765 Share on other sites More sharing options...
Solarpitch Posted July 4, 2008 Author Share Posted July 4, 2008 Yup.. I was uploading the file to the wrong directory. What I had first just works fine. Sorry for wasting your time... now where's that self ban button.... Link to comment https://forums.phpfreaks.com/topic/113239-solved-str-replace-question/#findComment-581767 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.