JPERKS1985
asked on
whats wrong w/ this script?
<?
if((isset($_SERVER["HTTP_U
$_SERVER["QUERY_STRING"]==
{
} else {
echo 'yo';
}
?>
Fatal error: Call to undefined function: stripos() in /homdex.php on line 5
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Never mind. I misread the function name. What version of PHP are you using?
bol
bol
If you don't know the version you can use phpinfo() to find out. Make a page with just the lines below in it and save it as phpinfo.php. Then run it in your browser.
<?php
phpinfo();
?>
It looks like Steelseth12 is thinking the same thing. :)
bol
<?php
phpinfo();
?>
It looks like Steelseth12 is thinking the same thing. :)
bol
you could use stripos(strtolower($_SERVE R["HTTP_US ER_AGENT"] ), "hey")
What I do if I know I'll require a function that may not exist is to create it myself in php and wrap it in a conditional if the function does not exist.
This way you can use the newer functions on older versions of php!
Taken from the pear package 'php_compat'
--------
if (!function_exists('stripos ')) {
function stripos($haystack, $needle, $offset = null)
{
if (!is_scalar($haystack)) {
user_error('stripos() expects parameter 1 to be string, ' .
gettype($haystack) . ' given', E_USER_WARNING);
return false;
}
if (!is_scalar($needle)) {
user_error('stripos() needle is not a string or an integer.', E_USER_WARNING);
return false;
}
if (!is_int($offset) && !is_bool($offset) && !is_null($offset)) {
user_error('stripos() expects parameter 3 to be long, ' .
gettype($offset) . ' given', E_USER_WARNING);
return false;
}
// Manipulate the string if there is an offset
$fix = 0;
if (!is_null($offset)) {
if ($offset > 0) {
$haystack = substr($haystack, $offset, strlen($haystack) - $offset);
$fix = $offset;
}
}
$segments = explode(strtolower($needle ), strtolower($haystack), 2);
// Check there was a match
if (count($segments) === 1) {
return false;
}
$position = strlen($segments[0]) + $fix;
return $position;
}
}
--------
This way you can use the newer functions on older versions of php!
Taken from the pear package 'php_compat'
--------
if (!function_exists('stripos
function stripos($haystack, $needle, $offset = null)
{
if (!is_scalar($haystack)) {
user_error('stripos() expects parameter 1 to be string, ' .
gettype($haystack) . ' given', E_USER_WARNING);
return false;
}
if (!is_scalar($needle)) {
user_error('stripos() needle is not a string or an integer.', E_USER_WARNING);
return false;
}
if (!is_int($offset) && !is_bool($offset) && !is_null($offset)) {
user_error('stripos() expects parameter 3 to be long, ' .
gettype($offset) . ' given', E_USER_WARNING);
return false;
}
// Manipulate the string if there is an offset
$fix = 0;
if (!is_null($offset)) {
if ($offset > 0) {
$haystack = substr($haystack, $offset, strlen($haystack) - $offset);
$fix = $offset;
}
}
$segments = explode(strtolower($needle
// Check there was a match
if (count($segments) === 1) {
return false;
}
$position = strlen($segments[0]) + $fix;
return $position;
}
}
--------
I'm glad I could help. Thank you for the grade, the points and the fun question.
bol
bol
more info at http://www.php.net/manual/en/function.stripos.php