MemoryRefresh!

Parse



Questions 1 Answers 0%

Pages   0 from 51
Questions   0 from 84

Reset



* parse_str ()
<?php // Parses the string into variables // test.php?a=1&&c[]=3&c[]=4 parse_str($_SERVER['QUERY_STRING']); echo $a; // 1 echo $c[1]; // 4 * parse_url()
<?php // Parse a URL and return its components $parts = parse_url("http://doc.com/test.php?a=1&b=c"); print_r($parts); /* Array ( [scheme] => http [host] => doc.com [path] => /test.php [query] => a=1&b=c ) */ * strtok(), strrtok() Note that only the first call to strtok uses the string argument.
<?php // Splits a string (str) into smaller strings (tokens) $str = "java.lang.Object"; echo $tok_1 = strtok("java.lang.Object", "."); // java echo $tok_2 = strtok("."); // lang // Get the last part of a string after a given character echo strrev(strtok(strrev("java.lang.Object"), ".")); // tcejbO.gnal.avaj -> tcejbO -> Object
<?php // like strstr() echo strtok("name@doc.com", "@"); // name * strspn() Match a string against a "whitelist" mask of allowed characters
<?php // Returns the length of the initial segment of the string that does contain // any of the characters from the mask echo strspn("133445ab123ef", "12345"); // 6 echo strspn("133ab12345ef", "12345"); // 3 echo strspn("ab12345ef", "12345"); // 0 // Using a start & length to search echo strspn("ab12345ef", "12345", 2); // 5 echo strspn("ab12345ef", "12345", 2, 1); // 1
<?php // You can use this function with strlen to check illegal characters. // This function is significantly faster than the equivalent preg_match() $allowed = "0123456789+. "; $phone = "Phone: +021 072.88.544545"; $phone2 = "+021 072.88.544545 (phone)"; echo strspn($phone, $allowed); // 0 echo strspn($phone2, $allowed); // 19 $allowed = "0123456789+. "; $phone = "+021 / 072.88.544545"; if (strlen($phone) == strspn($phone, $allowed)) { echo "allowed"; // not true becouse of "/" char }
Questions

Related pages

Basics !
Comparing !
Searching !
Parse !
Replacing !
Formatting !
Printf !
Regexp !
Datetime !


0% 100%
 
 
0 pages 51 pages
1) If current url is given, how do you get the $a value? <?php $url = "http://mysite.com/test.php?a=1"




2) What is the value of a? <?php parse_str("a=1&b=2&a[]=2&a[]=3");






Last Review: n/a   Passed: n/a   Reviews: n/a   Next Review: n/a  


* parse_str ()
<?php // Parses the string into variables // test.php?a=1&&c[]=3&c[]=4 parse_str($_SERVER['QUERY_STRING']); echo $a; // 1 echo $c[1]; // 4 * parse_url()
<?php // Parse a URL and return its components $parts = parse_url("http://doc.com/test.php?a=1&b=c"); print_r($parts); /* Array ( [scheme] => http [host] => doc.com [path] => /test.php [query] => a=1&b=c ) */ * strtok(), strrtok() Note that only the first call to strtok uses the string argument.
<?php // Splits a string (str) into smaller strings (tokens) $str = "java.lang.Object"; echo $tok_1 = strtok("java.lang.Object", "."); // java echo $tok_2 = strtok("."); // lang // Get the last part of a string after a given character echo strrev(strtok(strrev("java.lang.Object"), ".")); // tcejbO.gnal.avaj -> tcejbO -> Object
<?php // like strstr() echo strtok("name@doc.com", "@"); // name * strspn() Match a string against a "whitelist" mask of allowed characters
<?php // Returns the length of the initial segment of the string that does contain // any of the characters from the mask echo strspn("133445ab123ef", "12345"); // 6 echo strspn("133ab12345ef", "12345"); // 3 echo strspn("ab12345ef", "12345"); // 0 // Using a start & length to search echo strspn("ab12345ef", "12345", 2); // 5 echo strspn("ab12345ef", "12345", 2, 1); // 1
<?php // You can use this function with strlen to check illegal characters. // This function is significantly faster than the equivalent preg_match() $allowed = "0123456789+. "; $phone = "Phone: +021 072.88.544545"; $phone2 = "+021 072.88.544545 (phone)"; echo strspn($phone, $allowed); // 0 echo strspn($phone2, $allowed); // 19 $allowed = "0123456789+. "; $phone = "+021 / 072.88.544545"; if (strlen($phone) == strspn($phone, $allowed)) { echo "allowed"; // not true becouse of "/" char }



More from Php

Basics
Variables
Operators
Function
Array
String
Streams
Uncategorized


More from Programming

Php
jQuery




Powered by minte9.com