Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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
 
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/
 
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 :)
 
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...
 
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.

 
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 ;)




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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.