Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 06-16-2003, 03:35 PM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
regular expressions - extract a string

i need to extract the version number out of the $_SERVER['HTTP_USER_AGENT'] with php.

for example .. the string might look like this:
Code:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Opera 7.11 [en]
i need to find and extract "Opera 7.11" out of there.

For this senerio, lets say that Opera will always preceed the version number.

Opera [0-9].[0-9]{2}

some expression like that .. but i'm not sure how to get the version number into a variable.

any ideas?
__________________
Mike
sde is offline   Reply With Quote
Old 06-16-2003, 04:05 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
no regex .. here's the function:
PHP Code:
<?
function getVersion($preceeding,$version_length)
{
  
$start=strpos($_SERVER['HTTP_USER_AGENT'],$preceeding);
  
$start=$start+strlen($preceeding);
  return 
substr($_SERVER['HTTP_USER_AGENT'],$start,$version_length);
}
?>
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help for another program Androto Standard C, C++ 54 10-15-2004 08:21 AM
From C to Java HighterDK Java 11 07-13-2004 08:15 PM
PHP Regular Expressions Epsilon PHP 5 12-24-2003 08:36 AM


All times are GMT -8. The time now is 10:14 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting