Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 31st, 2005, 03:01 PM
Friend of Wrox
 
Join Date: Dec 2004
Location: London, London, United Kingdom.
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts
Default Search string

Something quite easy (if you know how to.. which officialy I don't!!)

I'm looking at isolating the browser name from the HTTP_USER_AGENT ..
Anyone know how to do this?

I'm looking for something like:
$Sname=$_SERVER['HTTP_USER_AGENT'];
if (stringsearch($Sname)="FireFox") {firefox=1;}
if (stringsearch($Sname)="Netscape") {Netscape=1;}
if (stringsearch($Sname)="MSIE") {MS=1;}

Thanks
Reply With Quote
  #2 (permalink)  
Old June 1st, 2005, 04:31 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

You need use strpos()
See a similar complete example http://www.mediasworks.com/scripts/
Reply With Quote
  #3 (permalink)  
Old June 1st, 2005, 04:41 AM
Friend of Wrox
 
Join Date: Dec 2004
Location: London, London, United Kingdom.
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thats looking good - thks :)
Reply With Quote
  #4 (permalink)  
Old June 1st, 2005, 05:21 AM
Friend of Wrox
 
Join Date: Dec 2004
Location: London, London, United Kingdom.
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts
Default

A quicky .. I think there's a bug in PHP using strpos() - if anyone wants to check it and post it to Mr PHP

if your string="BlackBerry3270/5.3.1" and you do:
if(strpos(string, "BlackBerry") == true) { echo "Blackberry web browser detected"; }
That doesn't work.. However if you do:
if(strpos(string, "lackBerry") == true) { echo "Blackberry web browser detected"; }
That work fine.. so officialy strpos() isn't checking the 1st caracter...
Reply With Quote
  #5 (permalink)  
Old June 2nd, 2005, 01:27 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

True.

echo strpos($string, "BlackBerry"); // displays '0'
echo strpos($string, "BBlackBerry"); // displays 'nothing', NULL?

I tried to comapre it with 'NULL', still, it not yields!!

so,
Quote:
quote:if(gettype(strpos($string, "BlackBerry"))=="integer")
    echo "Blackberry web browser detected";

is fine as strpos() returns string position in integer, and NULL? when it not finds..

Alternatively, you may use preg_match() or preg_match_all() functions for absolute-n-powerful matching; these are PHP functions supporting PCRE. It'll take you a while to learn regex ( if you don't know ), but it's a worthy stuff, to invest time.

Reply With Quote
  #6 (permalink)  
Old June 2nd, 2005, 03:30 AM
Friend of Wrox
 
Join Date: Dec 2004
Location: London, London, United Kingdom.
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just changed $String=" ".$_SERVER['HTTP_USER_AGENT'];
I'm not for complication ;)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
New text search doesn't preselect search string planoie Visual Studio 2005 0 July 23rd, 2007 06:47 AM
Search string in Excel Echo10 Excel VBA 1 June 1st, 2006 11:11 PM
Search certain charactor/ symbol in my string life_s Ng General .NET 3 January 4th, 2005 08:48 AM
MSAccess search string question gilgalbiblewheel Access 2 August 3rd, 2004 06:01 PM
Search for Character in String Kaynor09 Excel VBA 2 April 24th, 2004 11:13 AM



All times are GMT -4. The time now is 03:44 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.