NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page need help with preg match

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-01-2007, 07:08 AM THREAD STARTER               #1 (permalink)
Senior Member
 
champ_rock's Avatar
Join Date: Oct 2006
Location: http://akshayjain.org
Posts: 2,830
champ_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond repute
 



need help with preg match


hi

i suppose i have some raw data in the form
Quote:
name: champ rock
????: NamePros.com http://www.namepros.com/programming/322937-need-help-with-preg-match.html
DOB: blah blah
age: blah blah
address: blah blah blah
now i want to use preg_match to extract only the name i.e. champ rock (anything after "name: " field)

please tell me what code i should use for that?
champ_rock is offline  
Old 05-01-2007, 07:45 AM   #2 (permalink)
NamePros Member
Join Date: Apr 2005
Posts: 117
mikesherov will become famous soon enoughmikesherov will become famous soon enough
 



if that data is stored in the variable $string...

Code:
$lines=file($string);
foreach($lines as $line){
 if(substr($line,0,5)=="name:"){
  $answer=substr($line,6);
 }
}
echo($answer);
I'm sure there is a more efficient answer using preg_match like you wanted, but this does the trick too...
mikesherov is offline  
Old 05-01-2007, 08:50 AM   #3 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
PHP Code:
preg_match("/name:([^\n]*)?/i"$data$matches);
 
$name trim($matches[1]); 
????: NamePros.com http://www.namepros.com/showthread.php?t=322937
Dan is offline  
Old 05-01-2007, 09:13 PM THREAD STARTER               #4 (permalink)
Senior Member
 
champ_rock's Avatar
Join Date: Oct 2006
Location: http://akshayjain.org
Posts: 2,830
champ_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond reputechamp_rock has a reputation beyond repute
 



Originally Posted by Dan
PHP Code:
preg_match("/name:([^\n]*)?/i"$data$matches);
????: NamePros.com http://www.namepros.com/showthread.php?t=322937
 
$name trim($matches[1]); 
@Dan i have sent u a PM with my script.. it would be very kind of you if u could have a look at the script and tell me where i am going wrong

thanks a lot
champ_rock is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 02:04 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger