Lisa23 Posted September 7, 2011 Share Posted September 7, 2011 Hi i have a query that retrives fields from the database now i have a query now on the form teh user has to put sign (£) i am trying to grab that row and evrytime it finds the (£) on that particular field replace when it echo the row film_price replace any (£) signs with (£) Example on the databse the user typed £45 to £55 when echo that row on html replace the (£) signs with html (£) which is (£) i have tried but didnt echo the row what i am doing wrong? <?php $vOriginalString = $film_price; $vSomeSpecialChars = array("£", "$"); $vReplacementChars = array("£ POA", "£ POA"); $vReplacedString = str_replace($vOriginalString); echo $vReplacedString; ?> Quote Link to comment https://forums.phpfreaks.com/topic/246621-replacement-string-that-comes-from-database/ Share on other sites More sharing options...
JKG Posted September 7, 2011 Share Posted September 7, 2011 <? $film_price = '£1000'; echo str_replace('£', '£', $film_price); //prints £1000 ?> get rid of the arrays. Quote Link to comment https://forums.phpfreaks.com/topic/246621-replacement-string-that-comes-from-database/#findComment-1266394 Share on other sites More sharing options...
Lisa23 Posted September 7, 2011 Author Share Posted September 7, 2011 that film is value is coming from the database i have a query with the fetch function that pick up the film price from the database like so i dnt know the value has it coming from the database $film_price= $row['film_price']; can i put it like <? $film_price = .$row['film_price'].; echo str_replace('£', '£', $film_price); //prints £1000 ?> Quote Link to comment https://forums.phpfreaks.com/topic/246621-replacement-string-that-comes-from-database/#findComment-1266397 Share on other sites More sharing options...
JKG Posted September 7, 2011 Share Posted September 7, 2011 str_replace('£', '£', $row['film_price']); or $film_price = $row['film_price']; str_replace('£', '£', $film_price); Quote Link to comment https://forums.phpfreaks.com/topic/246621-replacement-string-that-comes-from-database/#findComment-1266398 Share on other sites More sharing options...
Pikachu2000 Posted September 7, 2011 Share Posted September 7, 2011 There's a built in function that does that: htmlentities. $film_price = htmlentities($film_price); Quote Link to comment https://forums.phpfreaks.com/topic/246621-replacement-string-that-comes-from-database/#findComment-1266402 Share on other sites More sharing options...
Lisa23 Posted September 7, 2011 Author Share Posted September 7, 2011 i'm a lil confused now my code is something like this not (full fetch query) but i then try echo the film price, doesnt echo on the fetch query i have this line $viewing_price=($film_price); i'm presuming that is saying $viewing_price now has the value of film_price so to echo film price instead of echo $film_price ? it is echo $viewing_price correct ? at the botton of the code is my try on the replacemen i'm confused on what should echo and replace string be $connection = @mysql_connect($db_address,$db_username,$db_password) or die("Couldn't CONNECT."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select DATABASE."); //SELECT All based on current cookie Information $query="SELECT * FROM films WHERE (film_filename = '$id')"; $result = mysql_query($query) or die("Couldn't execute QUERY."); if($jrpmerrorstatus=="1") { $film_qty = mysql_num_rows($result ); print("FOUND: $film_qty<BR>"); } while ($row = mysql_fetch_array($result)) { $film_price = $row['film_location_price']; if($film_addr01=="" || $film_addr01=="X") $viewing_price=($film_price); mysql_close($connection); <?php <?php $viewing_price = $row['film_price']; str_replace('£', '£', $film_price); ?> <?php print $film_price; ?> Quote Link to comment https://forums.phpfreaks.com/topic/246621-replacement-string-that-comes-from-database/#findComment-1266407 Share on other sites More sharing options...
Lisa23 Posted September 7, 2011 Author Share Posted September 7, 2011 Gi i have tried the htmlentities <?php $userInputEntities = htmlentities($viewing_price); //Now we can display it echo $viewing_price; ?> but still echo the (?) instead of hrml (£) sign Quote Link to comment https://forums.phpfreaks.com/topic/246621-replacement-string-that-comes-from-database/#findComment-1266411 Share on other sites More sharing options...
Pikachu2000 Posted September 7, 2011 Share Posted September 7, 2011 What's in the HTML source? Does it show £? Quote Link to comment https://forums.phpfreaks.com/topic/246621-replacement-string-that-comes-from-database/#findComment-1266413 Share on other sites More sharing options...
darkfreaks Posted September 7, 2011 Share Posted September 7, 2011 http://www.codeunit.co.za/2011/06/27/php-how-to-html-entity-decode-an-euro-symbol/ Quote Link to comment https://forums.phpfreaks.com/topic/246621-replacement-string-that-comes-from-database/#findComment-1266539 Share on other sites More sharing options...
Lisa23 Posted September 7, 2011 Author Share Posted September 7, 2011 Thank you all for the help @darkfreaks link fixed the problem by just having the metatag like this the above code worked fine Thank you all for the help <meta content="text/html; charset=iso-8859-15" http-equiv="Content-Type"> <?php $userInputEntities = htmlentities($viewing_price); //Now we can display it echo $viewing_price; ?> Quote Link to comment https://forums.phpfreaks.com/topic/246621-replacement-string-that-comes-from-database/#findComment-1266576 Share on other sites More sharing options...
darkfreaks Posted September 7, 2011 Share Posted September 7, 2011 no problem don't forget to mark topic as solved Quote Link to comment https://forums.phpfreaks.com/topic/246621-replacement-string-that-comes-from-database/#findComment-1266595 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.