SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Apr 2010
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Replacement string that comes from database

    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 (&pound)

    Example on the databse the user typed £45 to £55 when echo that row on html replace the (£) signs with html (£) which is (&pound) i have tried

    but didnt echo the row what i am doing wrong?
    PHP Code:
    <?php
      $vOriginalString 
    $film_price;
      
    $vSomeSpecialChars = array("£""$");
      
    $vReplacementChars = array("&pound POA""&pound POA");
      
    $vReplacedString str_replace($vOriginalString);

      echo 
    $vReplacedString;
    ?>

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Your code won't work because your only supplying the str_replace() function with one argument when it requires three, see the updated code below which should work fine.

    PHP Code:
    <?php

      $vOriginalString 
    $film_price;
      
    $vSomeSpecialChars = array("£""$");
      
    $vReplacementChars "&pound; POA";
      
    $vReplacedString str_replace($vSomeSpecialChars$vReplacementChars$vOriginalString);

      echo 
    $vReplacedString;

    ?>
    Also as a note, when using special character codes such as "pound" you always need to end it with a semicolon ";" otherwise the browser will skip over it and read it as plain text.

  3. #3
    SitePoint Addict
    Join Date
    Apr 2010
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help this way did the job
    PHP Code:
    <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;
    ?>

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    Or simply switch to UTF-8 and keep the pound as is
    Let's call a spade a spade; ISO-8859-* sucks (not as much as the proprietary CP-* crap though).
    (yeah, I don't like character sets, does it show? )
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •