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 PHP preg expressions...

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

Advanced Search
5 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 01-06-2004, 09:01 PM THREAD STARTER               #1 (permalink)
NamePros Regular
 
CreativeLogic's Avatar
Join Date: Sep 2003
Posts: 889
CreativeLogic has a spectacular aura aboutCreativeLogic has a spectacular aura about
 



PHP preg expressions...


I have this file full of text. It was actually a select drop down field. I want to insert everything into the database so I need to seperate everything in it even the optgroups. Ive tried everything I can think of...

Here is the file:Link

Here is an exampe of how I want it to be displayed (its the first one):
Code:
"Automobiles / Vehicles"
4X4/SUVs
Acura
Aston Martin
Audio / Video
BMW
Bugatti
Buick
Cadillac
Chevrolet
Chrysler
Citroen
Classic
Cobra
Convertibles
Electronics
Exotic
Ferrari
Ford
Formula 1
Hummer
Hydrogen Powered
Insurance
Jeeps
Land Rover
Land Rovers
Leased
Lexus
Mazda
Mercedes-Benz
Motorcycles
Muscle Cars
NASCAR
New
Nissan
Peugeot
Pickup Trucks
Pontiac
Porsche
Private Pilot
Racing
Recreational Vehicles (RVs)
Renault
Repair
Rolls Royce
Shopping
Sports Bikes
Taxi
Technology/Engineering
Toyota
Used
Volkswagen
Z cars
__________________
Online Time Tracking :)
CreativeLogic is offline  
Old 01-07-2004, 12:01 AM   #2 (permalink)
Senior Member
Join Date: May 2003
Posts: 2,187
adam_uk is a jewel in the roughadam_uk is a jewel in the roughadam_uk is a jewel in the rough
 


Breast Cancer
just inser them manually via phpmyadmin, will be alot quick and easier
adam_uk is offline  
Old 01-07-2004, 04:09 AM THREAD STARTER               #3 (permalink)
NamePros Regular
 
CreativeLogic's Avatar
Join Date: Sep 2003
Posts: 889
CreativeLogic has a spectacular aura aboutCreativeLogic has a spectacular aura about
 



...Yea right... Would take at least twice as long...
__________________
Online Time Tracking :)
CreativeLogic is offline  
Old 01-07-2004, 07:39 AM   #4 (permalink)
NamePros Member
Join Date: Jul 2003
Location: Canterbury, UK
Posts: 99
samscripts is on a distinguished road
 



Hi, just use 2 "preg_match_all" function calls and a bit of php inbetween them to build up an array of optiongroups / options:

PHP Code:
<?php

$data 
join(""file("http://www.yaproom.com/interests.txt"));

$optgroups = array();

if( 
preg_match_all('/<optgroup label="(.*?)">(.*?)<\/optgroup>/is'$data$matches ) ){
    
$cnt count($matches[1]);
????: NamePros.com http://www.namepros.com/programming/16703-php-preg-expressions.html
    for( 
$i 0$i $cnt$i++){
        
$optgroups[$matches[1][$i]] = array();
        if( 
preg_match_all("/<option value='[0-9]*'>(.*?)<\/option>/is"$matches[2][$i], $options) ){
            
$cnt2 count($options[1]);
            for( 
$j 0$j $cnt2$j++){
                
$option $options[1][$j];
                
$optgroups[$matches[1][$i]][] = $option;
????: NamePros.com http://www.namepros.com/showthread.php?t=16703
            }
        }
    }
}

foreach( 
$optgroups as $n=>$options ){
    echo 
'"'.$n.'"';
    echo 
"\n";
    echo 
join("\n"$options)."\n";    
}

?>
That will print out a text list in the format you listed in your post (optgroup name in "" followed by a list of option names, etc)

$optgroups will be an array like this:

array (
"Option Group 1" => array("Option 1", "Option2", etc),
"Option Group 2" => array("Option 1", "Option2", etc),
etc, etc

So you can just step through the array and insert data into mysql with mysql_query()s...

hope that helps,

Sam
samscripts is offline  
Old 01-07-2004, 09:14 AM THREAD STARTER               #5 (permalink)
NamePros Regular
 
CreativeLogic's Avatar
Join Date: Sep 2003
Posts: 889
CreativeLogic has a spectacular aura aboutCreativeLogic has a spectacular aura about
 



Thanks I haven't tested it but that preg expressions looks like what I needed... Thanks...
__________________
Online Time Tracking :)
CreativeLogic is offline  
Closed Thread


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


 
All times are GMT -7. The time now is 02:09 PM.

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