[advanced search]
Results from the most recent live auction are here.
20 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Programming
User Name
Password

Old 01-06-2004, 10:01 PM   · #1
CreativeLogic
NamePros Regular
 
CreativeLogic's Avatar
 
Name: Ryan Amos
Trader Rating: (15)
Join Date: Sep 2003
Posts: 893
NP$: 18.00 (Donate)
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


Please register or log-in into NamePros to hide ads
__________________
Online Time Tracking
CreativeLogic is offline   Reply With Quote
Old 01-07-2004, 01:01 AM   · #2
adam_uk
Senior Member
 
Trader Rating: (17)
Join Date: May 2003
Posts: 2,211
NP$: 6170.25 (Donate)
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   Reply With Quote
Old 01-07-2004, 05:09 AM   · #3
CreativeLogic
NamePros Regular
 
CreativeLogic's Avatar
 
Name: Ryan Amos
Trader Rating: (15)
Join Date: Sep 2003
Posts: 893
NP$: 18.00 (Donate)
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   Reply With Quote
Old 01-07-2004, 08:39 AM   · #4
samscripts
NamePros Member
 
Name: Sam Yapp
Location: Canterbury, UK
Trader Rating: (7)
Join Date: Jul 2003
Posts: 99
NP$: 0.00 (Donate)
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]);
    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;
            }
        }
    }
}

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 online now   Reply With Quote
Old 01-07-2004, 10:14 AM   · #5
CreativeLogic
NamePros Regular
 
CreativeLogic's Avatar
 
Name: Ryan Amos
Trader Rating: (15)
Join Date: Sep 2003
Posts: 893
NP$: 18.00 (Donate)
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   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


Site Sponsors
Hunting Moon Hunting Moon Arcade Script
Advertise your business at NamePros
All times are GMT -7. The time now is 09:17 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0