Re: [PHP] Re: Php filter validate url
On 27 Jun 2011 at 00:15, Richard Riley rile...@googlemail.com wrote: In addition your content type in your post is incorrect. Your header contains Content-Type: multipart/alternative; boundary=00151747b53cf2927204a6a46ebb But its not multipart. This happens a lot in this group and I dont experience it elsewhere so I dont know if its a php programmer thing, an gmane artifact or something the mailing list does. I couldn't see anything in RFC2046, section 5.1.4, to suggest that multipart/alternative *requires* that there be more than one part. And why does it matter, anyway? -- Cheers -- Tim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Php filter validate url
On Sun, Jun 26, 2011 at 5:44 PM, Shawn McKenzie nos...@mckenzies.net wrote: On 06/26/2011 12:31 PM, Adam Tong wrote: Hi, I wanted tu use php filters for validation to avoid regular expresions. Is it possible that FILTER_VALIDATE_URL only checks if the string has http:// and do not check for the format domain.something? $url = 'http://wwwtestcom'; $url = filter_var($url,FILTER_VALIDATE_URL); echo $url; - Or I am doing something wrong Thank you Unless I'm totally misunderstanding what you want (validate that a string starts with http://) try: if(strpos($url, 'http://') === 0) { //starts with http:// } esle { // does not start with http:// } -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Another possible solution could be: $ary = explode('://', $url); if (1 = count($ary)) { echo 'No schema specified!'; } else { // Schema specified. // $ary[0] is the protocol $allowed = array('http', 'https'); if (FALSE == in_array($ary[0], $allowed) { // Protocol not valid! exit(1); // or return FALSE; whatever... } // $ary[1] is the uri, validate with filter_var(). } Hope this helps. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Php filter validate url
On 06/27/2011 10:01 AM, Plamen Ivanov wrote: On Sun, Jun 26, 2011 at 5:44 PM, Shawn McKenzie nos...@mckenzies.net wrote: On 06/26/2011 12:31 PM, Adam Tong wrote: Hi, I wanted tu use php filters for validation to avoid regular expresions. Is it possible that FILTER_VALIDATE_URL only checks if the string has http:// and do not check for the format domain.something? $url = 'http://wwwtestcom'; $url = filter_var($url,FILTER_VALIDATE_URL); echo $url; - Or I am doing something wrong Thank you Unless I'm totally misunderstanding what you want (validate that a string starts with http://) try: if(strpos($url, 'http://') === 0) { //starts with http:// } esle { // does not start with http:// } -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Another possible solution could be: $ary = explode('://', $url); if (1 = count($ary)) { echo 'No schema specified!'; } else { // Schema specified. // $ary[0] is the protocol $allowed = array('http', 'https'); if (FALSE == in_array($ary[0], $allowed) { // Protocol not valid! exit(1); // or return FALSE; whatever... } // $ary[1] is the uri, validate with filter_var(). } Hope this helps. May make more sense to use parse_url() than explode. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Php filter validate url
On Mon, Jun 27, 2011 at 11:14 AM, Shawn McKenzie nos...@mckenzies.net wrote: On 06/27/2011 10:01 AM, Plamen Ivanov wrote: On Sun, Jun 26, 2011 at 5:44 PM, Shawn McKenzie nos...@mckenzies.net wrote: On 06/26/2011 12:31 PM, Adam Tong wrote: Hi, I wanted tu use php filters for validation to avoid regular expresions. Is it possible that FILTER_VALIDATE_URL only checks if the string has http:// and do not check for the format domain.something? $url = 'http://wwwtestcom'; $url = filter_var($url,FILTER_VALIDATE_URL); echo $url; - Or I am doing something wrong Thank you Unless I'm totally misunderstanding what you want (validate that a string starts with http://) try: if(strpos($url, 'http://') === 0) { //starts with http:// } esle { // does not start with http:// } -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Another possible solution could be: $ary = explode('://', $url); if (1 = count($ary)) { echo 'No schema specified!'; } else { // Schema specified. // $ary[0] is the protocol $allowed = array('http', 'https'); if (FALSE == in_array($ary[0], $allowed) { // Protocol not valid! exit(1); // or return FALSE; whatever... } // $ary[1] is the uri, validate with filter_var(). } Hope this helps. May make more sense to use parse_url() than explode. -- Thanks! -Shawn http://www.spidean.com http://php.net/manual/en/function.parse-url.php This function is not meant to validate the given URL... I would use parse_url() after URL validation. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Php filter validate url
On 6/27/2011 8:25 AM, Plamen Ivanov wrote: On Mon, Jun 27, 2011 at 11:14 AM, Shawn McKenzie nos...@mckenzies.net wrote: On 06/27/2011 10:01 AM, Plamen Ivanov wrote: On Sun, Jun 26, 2011 at 5:44 PM, Shawn McKenzie nos...@mckenzies.net wrote: On 06/26/2011 12:31 PM, Adam Tong wrote: Hi, I wanted tu use php filters for validation to avoid regular expresions. Is it possible that FILTER_VALIDATE_URL only checks if the string has http:// and do not check for the format domain.something? $url = 'http://wwwtestcom'; $url = filter_var($url,FILTER_VALIDATE_URL); echo $url; - Or I am doing something wrong Thank you Unless I'm totally misunderstanding what you want (validate that a string starts with http://) try: if(strpos($url, 'http://') === 0) { //starts with http:// } esle { // does not start with http:// } -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Another possible solution could be: $ary = explode('://', $url); if (1 = count($ary)) { echo 'No schema specified!'; } else { // Schema specified. // $ary[0] is the protocol $allowed = array('http', 'https'); if (FALSE == in_array($ary[0], $allowed) { // Protocol not valid! exit(1); // or return FALSE; whatever... } // $ary[1] is the uri, validate with filter_var(). } Hope this helps. May make more sense to use parse_url() than explode. -- Thanks! -Shawn http://www.spidean.com http://php.net/manual/en/function.parse-url.php This function is not meant to validate the given URL... I would use parse_url() after URL validation. Shawn meant to use parse_url() in place of your explode statement. He didn't say to use parse_url() as a method to validate the url. He said it would make more sense to do the following. Also, use strict type matching if you want to compare against boolean(FALSE) $allowed = array('http', 'https'); $scheme = parse_url($url, PHP_URL_SCHEME); if (FALSE === in_array($scheme, $allowed) { // Protocol not valid! exit(1); // or return FALSE; whatever... } Seems a little less muddy to me. Jim Lucas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Php filter validate url
On Mon, Jun 27, 2011 at 11:34 AM, Jim Lucas li...@cmsws.com wrote: On 6/27/2011 8:25 AM, Plamen Ivanov wrote: On Mon, Jun 27, 2011 at 11:14 AM, Shawn McKenzie nos...@mckenzies.net wrote: On 06/27/2011 10:01 AM, Plamen Ivanov wrote: On Sun, Jun 26, 2011 at 5:44 PM, Shawn McKenzie nos...@mckenzies.net wrote: On 06/26/2011 12:31 PM, Adam Tong wrote: Hi, I wanted tu use php filters for validation to avoid regular expresions. Is it possible that FILTER_VALIDATE_URL only checks if the string has http:// and do not check for the format domain.something? $url = 'http://wwwtestcom'; $url = filter_var($url,FILTER_VALIDATE_URL); echo $url; - Or I am doing something wrong Thank you Unless I'm totally misunderstanding what you want (validate that a string starts with http://) try: if(strpos($url, 'http://') === 0) { //starts with http:// } esle { // does not start with http:// } -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Another possible solution could be: $ary = explode('://', $url); if (1 = count($ary)) { echo 'No schema specified!'; } else { // Schema specified. // $ary[0] is the protocol $allowed = array('http', 'https'); if (FALSE == in_array($ary[0], $allowed) { // Protocol not valid! exit(1); // or return FALSE; whatever... } // $ary[1] is the uri, validate with filter_var(). } Hope this helps. May make more sense to use parse_url() than explode. -- Thanks! -Shawn http://www.spidean.com http://php.net/manual/en/function.parse-url.php This function is not meant to validate the given URL... I would use parse_url() after URL validation. Shawn meant to use parse_url() in place of your explode statement. He didn't say to use parse_url() as a method to validate the url. He said it would make more sense to do the following. Also, use strict type matching if you want to compare against boolean(FALSE) $allowed = array('http', 'https'); $scheme = parse_url($url, PHP_URL_SCHEME); if (FALSE === in_array($scheme, $allowed) { // Protocol not valid! exit(1); // or return FALSE; whatever... } Seems a little less muddy to me. Jim Lucas Makes sense now. Thanks guys. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Php filter validate url
On 06/26/2011 12:31 PM, Adam Tong wrote: Hi, I wanted tu use php filters for validation to avoid regular expresions. Is it possible that FILTER_VALIDATE_URL only checks if the string has http:// and do not check for the format domain.something? $url = 'http://wwwtestcom'; $url = filter_var($url,FILTER_VALIDATE_URL); echo $url; - Or I am doing something wrong Thank you No, because http:// is not a URL, it's a scheme or protocol. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Php filter validate url
On 06/26/2011 12:31 PM, Adam Tong wrote: Hi, I wanted tu use php filters for validation to avoid regular expresions. Is it possible that FILTER_VALIDATE_URL only checks if the string has http:// and do not check for the format domain.something? $url = 'http://wwwtestcom'; $url = filter_var($url,FILTER_VALIDATE_URL); echo $url; - Or I am doing something wrong Thank you Unless I'm totally misunderstanding what you want (validate that a string starts with http://) try: if(strpos($url, 'http://') === 0) { //starts with http:// } esle { // does not start with http:// } -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Php filter validate url
Guys, when you reply a mail, You should write your reply on the top of it, not at the bottom of it. makes it easier to follow. On Sun, Jun 26, 2011 at 11:44 PM, Shawn McKenzie nos...@mckenzies.netwrote: On 06/26/2011 12:31 PM, Adam Tong wrote: Hi, I wanted tu use php filters for validation to avoid regular expresions. Is it possible that FILTER_VALIDATE_URL only checks if the string has http:// and do not check for the format domain.something? $url = 'http://wwwtestcom'; $url = filter_var($url,FILTER_VALIDATE_URL); echo $url; - Or I am doing something wrong Thank you Unless I'm totally misunderstanding what you want (validate that a string starts with http://) try: if(strpos($url, 'http://') === 0) { //starts with http:// } esle { // does not start with http:// } -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Php filter validate url
On Sunday, 26 June 2011 at 22:50, Fatih P. wrote: Guys, when you reply a mail, You should write your reply on the top of it, not at the bottom of it. makes it easier to follow. This is a holy war, and not worth getting into again. The bottom line is that top posting breaks the rules, regardless of people's personal opinion of the merits of any particular posting style. http://php.net/reST/php-src/trunk_README.MAILINGLIST_RULES - item 3 near the bottom of the page. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Php filter validate url
well, anyway ignore it then On Sun, Jun 26, 2011 at 11:57 PM, Stuart Dallas stu...@3ft9.com wrote: On Sunday, 26 June 2011 at 22:50, Fatih P. wrote: Guys, when you reply a mail, You should write your reply on the top of it, not at the bottom of it. makes it easier to follow. This is a holy war, and not worth getting into again. The bottom line is that top posting breaks the rules, regardless of people's personal opinion of the merits of any particular posting style. http://php.net/reST/php-src/trunk_README.MAILINGLIST_RULES - item 3 near the bottom of the page. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/
Re: [PHP] Re: Php filter validate url
On Mon, 2011-06-27 at 00:00 +0200, Fatih P. wrote: well, anyway ignore it then On Sun, Jun 26, 2011 at 11:57 PM, Stuart Dallas stu...@3ft9.com wrote: On Sunday, 26 June 2011 at 22:50, Fatih P. wrote: Guys, when you reply a mail, You should write your reply on the top of it, not at the bottom of it. makes it easier to follow. This is a holy war, and not worth getting into again. The bottom line is that top posting breaks the rules, regardless of people's personal opinion of the merits of any particular posting style. http://php.net/reST/php-src/trunk_README.MAILINGLIST_RULES - item 3 near the bottom of the page. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ No, the bottom-posting is a rule for this list. Don't like it, you don't have to use the list. -- Thanks, Ash http://www.ashleysheridan.co.uk
[PHP] Re: Php filter validate url
In mailing lists and usenet you should never top post. You integrate your reply or follow up. This is well documented and makes sense in tech threads were context is everything. In adidition your content type in your post is incorrect. Your header contains Content-Type: multipart/alternative; boundary=00151747b53cf2927204a6a46ebb But its not multipart. This happens a lot in this group and I dont experience it elsewhere so I dont know if its a php programmer thing, an gmane artifact or something the mailing list does. Fatih P. fatihpirist...@gmail.com writes: -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Php filter validate url
On Mon, Jun 27, 2011 at 1:15 AM, Richard Riley rile...@googlemail.comwrote: In mailing lists and usenet you should never top post. You integrate your reply or follow up. This is well documented and makes sense in tech threads were context is everything. In adidition your content type in your post is incorrect. Your header contains Content-Type: multipart/alternative; boundary=00151747b53cf2927204a6a46ebb But its not multipart. This happens a lot in this group and I dont experience it elsewhere so I dont know if its a php programmer thing, an gmane artifact or something the mailing list does. Fatih P. fatihpirist...@gmail.com writes: -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php headers are set and sent by gmail itself Content-Type: multipart/alternative; boundary=00151747b53cf2927204a6a46ebb
Re: [PHP] Re: Php filter validate url
On 06/26/2011 04:50 PM, Fatih P. wrote: Guys, when you reply a mail, You should write your reply on the top of it, not at the bottom of it. makes it easier to follow. Ready flame-throwers! -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php