SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    619
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    string replace upper case to lowercase

    hi

    my select options are getting echo as upper case

    PHP Code:
    <select>
    <option><? echo strtoupper($row['category_name']); ?></option>
    </select>
    there are some option names that contain "&" sign. So I am replacing that sign with "&amp;"

    PHP Code:
    $row['category_name'] = str_replace("&""&amp;"$row['category_name']); 
    but this outputs "&amp" as uppercase "&AMP" which gives error while validating the code

    Code:
    WALL &AMP; CAR CHARGER
    how can i have "&amp" in lowercase and rest in uppercase

    vineet

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,897
    Mentioned
    138 Post(s)
    Tagged
    2 Thread(s)
    PHP Code:
    <select> 
    <option><? echo str_replace('&AMP;''&amp;'strtoupper($row['category_name'])); ?></option> 
    </select>
    Although it would be better to replace & with &amp; /AFTER/ you've converted the text to uppercase; escaping is always the last thing you should do, for exactly the reason you're asking this question

    So, better would be:

    PHP Code:
    <select> 
    <option><? echo htmlentities(strtoupper($row['category_name']), ENT_COMPAT'UTF-8'false); ?></option> 
    </select>
    and then remove the part where you replace & with &amp;
    Rémon - Hosting Advisor

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

  3. #3
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    619
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post

    So, better would be:

    PHP Code:
    <select> 
    <option><? echo htmlentities(strtoupper($row['category_name']), ENT_COMPAT'UTF-8'false); ?></option> 
    </select>
    thanks scallio

    this option is much better and works perfect

    vineet


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
  •