PHP substring comparisons...what kinds are there?

Reply

Join Date: Aug 2006
Posts: 999
Reputation: EnderX is an unknown quantity at this point 
Solved Threads: 1
EnderX EnderX is offline Offline
Posting Shark

PHP substring comparisons...what kinds are there?

 
0
  #1
Aug 3rd, 2007
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?
"No trees were harmed in the production of this post. However, several electrons were severely inconvenienced."

Kumquat.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,438
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 509
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: PHP substring comparisons...what kinds are there?

 
0
  #2
Aug 3rd, 2007
You might check your usage of the strstr() function, it may be a simple typo or something. The following works fine for me.
  1. <?php
  2. $s = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12";
  3. echo ($found=strstr($s,"Firefox")) ? $found : "(not found)";
  4. echo "<br>Firefox position: ".strpos($s,"Firefox");
  5.  
  6. echo "<br>Firefox removed..<br>";
  7.  
  8. $s = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 /1.5.0.12";
  9. echo ($found=strstr($s,"Firefox")) ? $found : "(not found)";
  10. echo "<br>Firefox position: ".strpos($s,"Firefox");
  11. ?>
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
Last edited by Ezzaral; Aug 3rd, 2007 at 6:31 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 42
Reputation: cereal is an unknown quantity at this point 
Solved Threads: 4
cereal cereal is offline Offline
Light Poster

Re: PHP substring comparisons...what kinds are there?

 
0
  #3
Aug 3rd, 2007
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC