| | |
PHP substring comparisons...what kinds are there?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2006
Posts: 999
Reputation:
Solved Threads: 1
I'm working on a php-built report that's supposed to be printed out. It may be used on IE, it may be used on Firefox, I'm not sure which and have no control over the issue. Differences in the output formatting of the two browsers mean I have to be able to trim the report at different places in order to keep everything looking neat. (Firefox should print landscape with 8 records per page, IE portrait with 10.)
I've found out about the HTTP_USER_AGENT variable. But, with both the strstr command and the stristr command, I can't seem to extract 'Firefox' from the Firefox user agent string, which shows up on echo as "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12".
The word Firefox is in there; I can see it. So why can my comparisons not seem to find it? And if the strstr and stristr functions don't see it, are there other php functions that might?
I've found out about the HTTP_USER_AGENT variable. But, with both the strstr command and the stristr command, I can't seem to extract 'Firefox' from the Firefox user agent string, which shows up on echo as "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12".
The word Firefox is in there; I can see it. So why can my comparisons not seem to find it? And if the strstr and stristr functions don't see it, are there other php functions that might?
"No trees were harmed in the production of this post. However, several electrons were severely inconvenienced."
Kumquat.
Kumquat.
You might check your usage of the strstr() function, it may be a simple typo or something. The following works fine for me. preg_match() is always an option if you need more complicated parsing.
Edit: The above was just a knock-up test demo - not my suggestion for code to check browser type
php Syntax (Toggle Plain Text)
<?php $s = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12"; echo ($found=strstr($s,"Firefox")) ? $found : "(not found)"; echo "<br>Firefox position: ".strpos($s,"Firefox"); echo "<br>Firefox removed..<br>"; $s = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 /1.5.0.12"; echo ($found=strstr($s,"Firefox")) ? $found : "(not found)"; echo "<br>Firefox position: ".strpos($s,"Firefox"); ?>
Edit: The above was just a knock-up test demo - not my suggestion for code to check browser type
Last edited by Ezzaral; Aug 3rd, 2007 at 6:31 pm.
•
•
Join Date: Aug 2007
Posts: 42
Reputation:
Solved Threads: 4
Or you can also try this script:
- http://mikecherim.com/experiments/su...r_sniffer.phps
Basically it uses eregi function to identify browsers and platforms. Bye
- http://mikecherim.com/experiments/su...r_sniffer.phps
Basically it uses eregi function to identify browsers and platforms. Bye
![]() |
Similar Threads
- Google, Yahoo and PHP (Search Engine Optimization)
- Hi I've been told by my bf that php and mysql are very very powerful tools in the com (PHP)
- Java or PHP? (IT Professionals' Lounge)
- PHP -I just don't know.. (PHP)
- php mysql help (PHP)
- PHP Beginner Here (PHP)
Other Threads in the PHP Forum
- Previous Thread: prevent scraping
- Next Thread: Related Searches/Queries Script.. Help!
| Thread Tools | Search this Thread |
# 5.2.10 alexa apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date directory display dissertation dropdown dynamic echo echo$_get[x]changingitintovariable... email encode error fairness file files folder form forms function functions google href htaccess html image images include indentedsubcategory insert ip javascript joomla legislation limit link local login mail memberships menu mlm multiple multipletables mysql mysqlquery newsletters oop open paypal pdf persist php problem provider query radio random recursion remote rss script search server sessions sms sockets source space spam sql syntax system table tutorial update upload url validator variable video web youtube






