Jump to content

[SOLVED] Str-Replace Question?


Solarpitch

Recommended Posts

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

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);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.