SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    USA
    Posts
    633
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php and textboxes

    Hi Guys

    I would like to know if this can be done in php.I saw this at the domain
    registrars website the other day

    Basically they have a textbox and ask you to list all your domains
    one row at a time.

    How then can we retrieve each row from the textbox and place it into an array


    I hope I have asked correctly

    Thank you
    DD

  2. #2
    SitePoint Addict telos's Avatar
    Join Date
    Mar 2005
    Location
    192.168.2.34
    Posts
    279
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Totally possible.

    PHP Code:
    $domains explode("\n",$_POST['textbox']);
    print_r($domains); 
    Or, if you want to separate them by commas:
    PHP Code:
    $domains explode(',',$_POST['textbox']);
    print_r($domains); 
    Or by spaces:
    PHP Code:
    $domains explode(' ',$_POST['textbox']);
    print_r($domains); 

  3. #3
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    USA
    Posts
    633
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by telos View Post
    Totally possible.

    PHP Code:
    $domains explode("\n",$_POST['textbox']);
    print_r($domains); 
    Or, if you want to separate them by commas:
    PHP Code:
    $domains explode(',',$_POST['textbox']);
    print_r($domains); 
    Or by spaces:
    PHP Code:
    $domains explode(' ',$_POST['textbox']);
    print_r($domains); 
    Thank you

    I get somthing like this

    Array ( [0] => domain1.com [1] => [2] => domain2.com [3] => domain3.com [4] => [5] => [6] => domain4.com [7] => domain5.com [8] => [9] => domain6.com [10] => )

    How do I remove these empty array keys, these are the empty lines

    I tried the solutions here http://www.phpbuilder.com/board/show...eadid=10248482

    but still no luck.

    Thanks
    DD

  4. #4
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    USA
    Posts
    633
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I also tried array_filter()

    Thanks
    DD

  5. #5
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php

    class DomainHandler {

        public 
    $domains;

        public function 
    __set($property$value)
        {
            
    $this->$property = (string)trim($value);
        }

        public function 
    __get($property)
        {
            return 
    $this->$property;
        }

        public function 
    callbackFunction($uri)
        {
            if (
    strlen($uri) >= 11) {
                if (
    false !== filter_var($uriFILTER_VALIDATE_URL)) {
                    return 
    true;
                }
            }
            return 
    false;
        }

        public function 
    buildDomainsArray()
        {
            
    $this->domains str_replace("\r""\n"$this->domains);
            
    $this->domains array_map('trim'explode("\n"$this->domains));
            
    $this->domains array_filter($this->domains,
                                          array(
    'self''callbackFunction'));
        }

        public function 
    __toString()
        {
            return (string)
    var_dump($this->domains);
        }

    }

    $domainHandler = new DomainHandler();
    $domainHandler->domains $_POST['domains'];
    $domainHandler->buildDomainsArray();
    echo 
    '<pre>'$domainHandler'</pre>';
    Maybe I have overcomplicated it a bit but it works

  6. #6
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A little improvement:

    PHP Code:
    <?php

    class DomainHandler {

        public 
    $domains;

        public function 
    __set($property$value)
        {
            
    $this->$property = (string)trim($value);
        }

        public function 
    __get($property)
        {
            return 
    $this->$property;
        }

        public function 
    callbackFunction($uri)
        {
            if (
    strlen($uri) >= 11) {
                if (
    false !== filter_var($uriFILTER_VALIDATE_URL)) {
                    return 
    true;
                }
            }
            return 
    false;
        }

        public function 
    buildDomainsArray($separator "\n")
        {
            if (
    "\n" === $separator) {
                
    $this->domains str_replace("\r""\n"$this->domains);
            }
            
    $this->domains array_map('trim'explode($separator$this->domains));
            
    $this->domains array_filter($this->domains,
                                          array(
    'self''callbackFunction'));
        }

        public function 
    __toString()
        {
            return 
    $this->domains;
        }

    }

    $domainHandler = new DomainHandler();
    $domainHandler->domains $_POST['domains'];
    $domainHandler->buildDomainsArray();

    echo 
    '<pre>';
    var_dump($domainHandler);
    echo 
    '</pre>';

  7. #7
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    USA
    Posts
    633
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by risoknop View Post
    A little improvement:

    PHP Code:
    <?php

    class DomainHandler {

        public 
    $domains;

        public function 
    __set($property$value)
        {
            
    $this->$property = (string)trim($value);
        }

        public function 
    __get($property)
        {
            return 
    $this->$property;
        }

        public function 
    callbackFunction($uri)
        {
            if (
    strlen($uri) >= 11) {
                if (
    false !== filter_var($uriFILTER_VALIDATE_URL)) {
                    return 
    true;
                }
            }
            return 
    false;
        }

        public function 
    buildDomainsArray($separator "\n")
        {
            if (
    "\n" === $separator) {
                
    $this->domains str_replace("\r""\n"$this->domains);
            }
            
    $this->domains array_map('trim'explode($separator$this->domains));
            
    $this->domains array_filter($this->domains,
                                          array(
    'self''callbackFunction'));
        }

        public function 
    __toString()
        {
            return 
    $this->domains;
        }

    }

    $domainHandler = new DomainHandler();
    $domainHandler->domains $_POST['domains'];
    $domainHandler->buildDomainsArray();

    echo 
    '<pre>';
    var_dump($domainHandler);
    echo 
    '</pre>';
    Thank you so much.

    DD


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
  •