SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard wheeler's Avatar
    Join Date
    Mar 2006
    Location
    Gold Coast, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    cleaning poorly formatted user input

    hello,

    I have found a solution to clean characters out of a string that I dont want in a URL
    PHP Code:
    function clean_string($string)
    {
       return 
    ereg_replace("[^[:space:]a-zA-Z0-9*_.-]"""$string);

    I notice that this still allows multiple spacing - how would I alter it to trim double+ spacing?

    *edit*

    this seems to work
    PHP Code:
    function url_string($string)
    {
        
    $string ereg_replace("[^[:space:]a-zA-Z0-9_.-]"""$string);
        
    $string trim($string);
        
    $string urlencode($string);
        
    $string ereg_replace("[+]+","+",$string);
       
       return 
    $string;

    Last edited by wheeler; Nov 20, 2006 at 22:54. Reason: learnt some more stuff
    Studiotime - Time Management for Web Developers
    to-do's, messages, invoicing, reporting - 30 day free trial!
    Thomas Multimedia Web Development

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $new preg_replace('/ {2,}/'' '$str); 


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
  •