SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    The Jellophonic Autobrain CHeeSeBLiND's Avatar
    Join Date
    Jul 2001
    Location
    Bolton, England
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Uppercase and lowercase

    i am currently working on a news script. In thenews script i have a function that that chnages peoples names into links to their bios. All the names and their details are stored in a database.

    im am currently using the 'str_replace' function to change 'name' into '<a href=bio.php?name=$name>$name</a> the only problme i have come across is that if in the database someones name is put down as 'james' and in the news script i type 'James' then the str_replace function does not change the name into a link so...

    how can i make it so that 'james', 'JAMES', 'James', 'JaMeS, etc are all recognised as the same thing?
    hmm...

  2. #2
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you're going about this the wrong way.

    im am currently using the 'str_replace' function to change 'name' into '<a href=bio.php?name=$name>$name</a>
    Don't do that.

    Do this

    PHP Code:

    print("<a href = \"bio.php?name=$name\">$name</a>"); 
    and if you want them all formatted the same do this

    PHP Code:
    $name ucfirst($name); 
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  3. #3
    The Jellophonic Autobrain CHeeSeBLiND's Avatar
    Join Date
    Jul 2001
    Location
    Bolton, England
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but if i do that wont it just change the name to a link if the first letter of the name is capitilised?

    PHP Code:
    <?PHP

    // Replace functions

    $result mysql_query("SELECT * FROM friends"); 

    while ( 
    $row mysql_fetch_array($result) ) {

    $entry str_replace("$row[name]""<a href=bio.php?name=$row[name]>$row[name]</a>"$entry);
    }

    ?>
    this is the function that im using currently...
    hmm...

  4. #4
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you replacing the name in an article or printing out the name and turning it into a link?
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  5. #5
    The Jellophonic Autobrain CHeeSeBLiND's Avatar
    Join Date
    Jul 2001
    Location
    Bolton, England
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im trying to make it so whenever someones name is mentioned on the news page the name is converted into a a link which points to that persons bio page.
    hmm...

  6. #6
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay.

    the name is always going to be mentioned in the articles like "James" right? If not you need to edit your articles.

    So get the input from the database and then run the ucfirst() function on it to format it like that, and then do a string replace.

    You could also use eregi_replace (which is a case insensitive replace function) but you should avoid using regular expressions unless you absolutely need too since there is more server overhead in running them.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums


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
  •