Jump to content

[SOLVED] Str-Replace Question?


Solarpitch

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.