Jump to content

Recommended Posts

I have a site that everything was typed manually, but I want to get all this info off so I can put all info into a database for easier editing and so forth.

 

I'm trying this code, which works to a point.

function curl($Url){
  
    if (!function_exists('curl_init')){
        die('cURL is not installed. Install and try again.');
    }
  
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch); 
 
$start = strpos($output, '<h2 style="text-align: center;"><span style="text-decoration: underline;">Alabama Tattoo Shops</span></h2>');
$end = strpos($output, '<p>', $start);
$length = $end-$start;
$site = substr($output, $start, $length);
 
$site = explode("<p>", $site);
 
foreach ($site AS $line) {
 
    print_r($line);
  }
 
    return $output; 
}
$site = curl('http://www.tattooshopusa.com/alabama/');
 
I don't understand how I can take the output and put the info into variables for easy insertion into the database.
 
Any help would be greatly appreciated.
 
Thanks in advance for your help
Link to comment
https://forums.phpfreaks.com/topic/291198-breaking-down-curl/
Share on other sites

You don't want to save html to a database.

 

You need to parse the exact data you need and give them a variable.

 

Some items to help you parse the data

simple html dom

preg_match_all()

preg_match()

dom

simplexml

 

The idea is to do pattern matching and on those values insert into a new array you create in the loop

 

As for making it able to insert, making new arrays in a loop.

foreach ($site AS $line) {
 $line_array[] = $line;//adding [] places them all in an array
    //print_r($line);
  }

//now outside the loop
print_r($line_array);//if need to see the new array

//you can then implode the array for inserts, although should clean everything first
$imploded = implode(",",$line_array);
echo $imploded;

You can also create associative arrays and key,value pairs

$new_array = array();
$new_array[] = array(
    "url" => $url,
    "title" => $title,
);
Link to comment
https://forums.phpfreaks.com/topic/291198-breaking-down-curl/#findComment-1491717
Share on other sites

Thank you for the reply, but it's not giving the desired results, everything is returned like this:

 

 

	
		
			
				Array
		
		
			
				 
			
				(
		
		
			
				 
			
				[0] => <h2 style="text-align: center;"><span style="text-decoration: underline;">Alabama Tattoo Shops</span></h2>
		
		
			
				 
			
				<hr style="border: 4px outset #DC143C;"/>
		
		
			
				 
			
				<p style="text-align: center;">A-1 Port City Tattooing & Body</p>
		
		
			
				 
			
				<p style="text-align: center;">5775 Gunn Rd</p>
		
		
			
				 
			
				<p style="text-align: center;">Mobile AL 36619</p>
		
		
			
				 
			
				<p style="text-align: center;">(251) 591-0846</p>
		
		
			
				 
			
				<hr style="border: 4px outset #DC143C;"/>
		
		
			
				 
			
				<p style="text-align: center;">Abro Inkworks</p>
		
		
			
				 
			
				<p style="text-align: center;">540 Main St</p>
		
		
			
				 
			
				<p style="text-align: center;">E Rainsville AL 35986</p>
		
		
			
				 
			
				<p style="text-align: center;">(256) 638-8360</p>
		
		
			
				 
			
				<hr style="border: 4px outset #DC143C;"/>
				

 

Everything seems to be in the single Array[0]

 

You can see what I'm talking about here

http://slapbackstudio.com/scrape.php

Link to comment
https://forums.phpfreaks.com/topic/291198-breaking-down-curl/#findComment-1491757
Share on other sites

I'm not sure what your code looks like, no idea what you tried.
 
I took the liberty to just place all the content of that page into a csv file, then a small script to make them into an array
 
read-csv.php

<?php
$my_file = "inkshops.csv";
if (file_exists($my_file)) {
$data = file($my_file);

foreach ($data as $line) {
$line = trim($line);
$explode_line = explode("|",$line);

$shop_name = trim($explode_line[0]);
$address_one = trim($explode_line[1]);
$address_two = trim($explode_line[2]);
$phone = trim($explode_line[3]);

//check if website exists
if($explode_line[4]){
$website = trim(strtolower($explode_line[4]));
}else{
$website = "NULL";
}

$shop_array[] = array(
    "shop_name" => $shop_name,
    "address_one" => $address_one,
    "address_two" => $address_two,
    "phone" => $phone,
    "website" => $website
);

}
//show the new array
echo '<pre>';
print_r($shop_array);
echo '</pre>';

}else{
echo $my_file."not found";
}
?>

inkshops.csv

A-1 Port City Tattooing & Body|5775 Gunn Rd|Mobile AL 36619|(251) 591-0846
Abro Inkworks|540 Main St|E Rainsville AL 35986|(256) 638-8360
Aerochild Tattoos|914 23rd St|S Birmingham AL 35205|(205) 328-9215
Aerochild.Com|Against All Odds Tattoos|Auburn AL 36830|(334) 821-7214
Against All Odds Tattoos|1908 Opelika Rd|Auburn AL 36830|(334) 887-5566|Againstalloddstattoo.Com
All The Rage Tattoo Studios|805 6th Ave|SE Decatur AL35601|(256) 355-5757
American Emporium|3939 Rucker Blvd|Enterprise AL 36330|(334) 308-2504
Art & Soul|1815 6th Ave SE # A|Decatur AL35601|(256) 580-3001
Artifacts Tattoos|300 Heflin Ave|E Birmingham AL 35214|(205) 639-1855
Artistic Addictions|500 S Quintard Ave|Anniston AL 36201|(256) 240-7075
Artistic Designs|904 Nuckolls St|Gadsden AL 35903|(256) 546-0996
Artistic Ink|12500 US Highway 431 # B|Guntersville AL 35976|(256) 582-2200|Artisticink.Com
B & E Tattoo Co|1443 Montgomery Hwy|Dothan AL 36303|(334) 677-7454
Bama Tattoo|2601 Leeman Ferry Rd SW # B1|Huntsville AL 35801|(256) 715-1615
Bama Tattoo|1804 Lurleen B Wallace Blvd|Northport AL 35476|(205) 764-0741
Blackbeard’s Tattoo Parlour|137 14th St|SW Decatur AL 35601|(256) 351-7500
Blackbeard’s Tattoo Parlour|1295 George Wallace Hwy|Russellville AL 35654|(256) 332-6100
Blue Rose Tattoo|1402 Memorial Pkwy|NW Huntsville AL 35801|(256) 533-4400|Thebluerosetattoo.Com
Body Language|2012 Woodward Ave|Muscle Shoals AL 35661|(256) 320-5742
Capitol City Tattoo|4127 Troy Hwy # C|Montgomery AL 36116|(334) 286-9070
Cloud Nine Permanent Cosmetics|1030 20th St|S Birmingham AL 35205|(205) 458-9998|Cloud9south.Com
CMB Tatoos|6398 University Dr|NW Huntsville AL 35806|(256) 726-9800
CMB Two|11065 Highway 231 431 N # 6|Meridianville AL 35759|(256) 715-0502
Core|1351 Mcfarland Blvd|Tuscaloosa AL 35401|(205) 561-2351
Cynical Tattoos Shop|2205 Lurleen B Wallace Blvd|Northport AL 35476|(205) 330-1070
Cynicaltattoos.Net|David’s Gallery|East 809 Gulf Shores Pkwy|Gulf Shores AL 36542|(251) 948-7862
Davy’s Professional Tattoo|6101 University Blvd|E Cottondale AL 35453|(205) 469-9212
Deep South Tattoos|1357 County Road 437|Cullman AL 35055|(256) 734-8966
Devotion Tattoo|3804 Governors Dr|SW Huntsville AL 35805|(256) 519-3338
Down South Bdy Arts & Piercing|5563 Jackson Rd Mobile AL 36619|(251) 660-6678
Dragon Trax Tattoo Piercing|6415 Highway 90|Theodore AL 36582|(251) 423-7867|Dragontraxtattoos.Com
Dream Land Skateboards|871 Cox Creek Pkwy|Florence AL 35630|(256) 766-2243
Eternal Art Tattoos|3380 Mcfarland Blvd # 3|Northport AL 35476|(205) 339-6112
Exit 13 Tattoo|1120 Shelton Beach Rd|Saraland AL 36571|(251) 675-1359
Flying Tiger Tattoo|1935 S College St|Auburn AL 36832|(334) 502-8822
Forbidden Images|121 W Crawford St|Dothan AL 36301|(334) 673-3554
Forever Ink|3226 Stillman Blvd|Tuscaloosa AL 35401|(205) 391-2171
Free Spirit Tattoos|13313 Highway|231 431 N Hazel|Green AL 35750|(256) 828-8939
Gulf Coast Tattoo Studio|7470 Theodore Dawes Rd|Theodore AL 36582|(251) 653-8063
Hole Truth|1009 S 4th St # C|Gadsden AL 35901|(256) 547-0100
Hot Rod Tat2|7914 Memorial Pkwy SW # A1|Huntsville AL 35802|(256) 489-2067
Images In Ink|US Highway 411|Odenville AL 35120|(205) 629-7638
Infinity Ink|1408 Pelham Rd|S Jacksonville AL 36265|(256) 782-1144
Ink City Tattoo|1029 6th Ave SE # B|Decatur AL 35601|(256) 306-9099
Ink City Tattoo|192 Putman Pkwy|Rogersville AL 35652|(256) 247-7740
Ink Factor|1665 E Main St|Prattville AL 36066|(334) 365-5545
Ink Factor2 LLC|105 N Burbank Dr|Montgomery AL 36117|(334) 356-2192
Ink Master Tatoo Inc|37135 US Highway 231 # 3|Ashville AL 35953|(205) 594-7305
Inked Addiction|253 8th Ave|Alexander City AL 35010|(256) 392-3330
Inkworx Tattoos|411 Jordan Ln NW # B|Huntsville AL 35805|(256) 217-0294
Jolly Kleen|1311 6th Ave|SE Decatur AL 35601|(256) 686-1410
Kaoz|330 S University Blvd|Mobile AL 36609|(251) 344-5343
Kreations Tattoos & Body Prcng|2022 Jordan Ln NW # E|Huntsville AL 35816|(256) 859-2545
L A Body Art By World Famous|221 1/2 Dauphin St # 12|Mobile AL 36602|(251) 423-0854|Myspace.Com/Tattoochattv
LA Body Art|422 Dauphin Island Pkwy|Mobile AL 36606|(251) 476-0008
Mad Tatters Tattoo & Body|3009 S Broad St # A|Scottsboro AL 35769|(256) 259-3858
Madtown Tattoos|107 Arlington|Dr Madison AL 35758|(256) 774-8282
Magic Needle Tattoo|417 Jordan Ln|NW Huntsville AL 35805|(256) 830-0102
Master’s Hand Tattoos & Metal|1247 S Oates St|Dothan AL 36301|(334) 699-2306
Mr D Tattoo & Good Smoke Tyme|808 US Highway 431|Boaz AL 35957|(256) 840-9040
N V Upscale Body Art & Prcngs|1221 Blount Ave|Guntersville AL 35976|(256) 486-3472
No Regrets Tattoo Studio|4820 University Dr NW # 34|Huntsville AL 35816|(256) 489-8875
Non Stop Art Tattoo|213 20th St|N Birmingham AL 35203|(205) 251-1119
Nuwave Tattoo Design|4057 Moffett Rd|Mobile AL 36618|(251) 219-7522
Old School Ink|944 Sutton Bridge Rd # 4|Rainbow City AL 35906|(256) 442-5331
Oni Ink Tattoos & Piercing|2415 E South Blvd # M|Montgomery AL 36116|(334) 284-3999
Outlaw Custom Tattoo|1736 E Main St|Prattville AL 36066|(334) 365-8666
Outlaw Tattoo Co|430 Twain Curv|Montgomery AL 36117|(334) 215-8152
Plan B Tattoos|730 Mitchell Blvd|Florence AL 35630|(256) 275-3661
Port City Tattoo|205 Dauphin St|Mobile AL 36602|(251) 415-3366
Pulse|24912 US Highway 72|Athens AL 35613|(256) 233-4655|Thepulsetattoos.Com
Randy’s Ink Spot Tattoo|3606 Highway 280|431 N Phenix City AL 36869|(334) 297-9117
Real Artist Tattoo Gallery|728 3rd Ave|W Birmingham AL 35204|(205) 202-4065
Revolution Ink|2961 Pelham Pkwy # 102|Pelham AL 35124|(205) 620-1350
Riverside Tattoo Studio|1763 Hamric Dr|E Oxford AL 36203|(256) 835-2705
Rocket City Tatoos|700 Pratt Ave NW # B3|Huntsville AL 35801|(256) 489-8282
Royal Street Tattoo|110 N Royal St|Mobile AL 36602|(251) 432-4772
Royal Street Tattoo|Eastern 28850 US Highway 98 # 107|Daphne AL 36526|(251) 447-0499
Royal Tattoo|3310 Governors Dr|SW Huntsville AL 35805|(256) 270-9450
Sacred Art Tatoos|104 Church St|Rainbow City AL 35906|(256) 413-1441
Screamers|1544 E Cottonwood Rd|Dothan AL 36301|(334) 794-3692
Screamers Tattoo|1005 US Highway 231|Brundidge AL 36010|(334) 808-4100
Screamers Tattoo|703 N Daleville Ave|Daleville AL 36322|(334) 503-1000
Screamers Tattoo & Body|1229 Rucker Blvd|Enterprise AL 36330|(334) 308-0289
Screamers Tattoo & Body|1394 El Paso Plz|Montgomery AL 36110|(334) 445-0737
Shenanigans Tattoo Parlor|422 S Gay St|Auburn AL 36830|(334) 821-7250|Autattoo.Com
Shogun Tattoos & Body Piercing|2200 S Oates St # B|Dothan AL 36301|(334) 794-8550
Showtime Tattoos|1028 15th St|Tuscaloosa AL 35401|(205) 331-4212
Skin Deep|1225 Snow St # 9|Oxford AL 36203|(256) 835-8442
Skin Deep Tattoo & Body Prcng|613 Highway 67|S Decatur AL 35603|(256) 686-1199
Skin Traditions Tattoos-Body|9483 Lee Road 246 # A|Smiths Station AL 36877|(334) 480-0770
Skin WORX Tattoo|2169 Pelham Pkwy|Pelham AL 35124|(205) 834-8700
Slow Fade Studio|10654 US Highway 31 # D|Spanish Fort AL 36527|(251) 621-3710
Southern Ink Tattoos & Prcngs|3335 Highway 14|Millbrook AL 36054|(334) 285-8400
Studio 25 Tattoo|1530 W I65 Service Rd S # C|Mobile AL 36693|(251) 660-2575
Symbolic Ink|307 Skyland Blvd|Tuscaloosa AL 35405|(205) 331-4522
Tat2 Town|6677 Three Notch Rd|Mobile AL 36619|(251) 666-2005
Tattoo Addiction|2275 Andrews Ave|Ozark AL 36360|(334) 443-8288
Tattoo Experience Studio|2703 University Blvd|E Tuscaloosa AL 35404|(205) 553-8313
Tattoo Expression|503 Cahaba Park Cir # B|Birmingham AL 35242|(205) 408-0502
Tattoo Expression|5712 Chalkville Rd # 120|Birmingham AL 35235|(205) 815-1174
Tattoo Jungle|4601 Highway 31 # E|Calera AL 35040|(205) 668-6566
Tattoo Shop|5818 Mcclellan Blvd|Anniston AL 36206|(256) 847-8282
Tattoo Shop|1531 Montgomery Hwy|Dothan AL 36303|(334) 699-7246
Tattoo Expression|5712 Chalkville Rd # 120|Birmingham AL 35235|(205) 815-1174
Tattoo Jungle|4601 Highway 31 # E|Calera AL 35040|(205) 668-6566
Tattoo Shop|5818 Mcclellan Blvd|Anniston AL 36206|(256) 847-8282
Tattoo Shop|1531 Montgomery Hwy|Dothan AL 36303|(334) 699-7246
Tattoo Shop|120 East St|N Talladega AL 35160|(256) 362-9246
Tattoo Zone|3722 Moffett Rd|Mobile AL 36618|(251) 460-2779
Tattooed Lady LLC|10099 Memorial Pkwy SW # 4|Huntsville AL 35803|(256) 489-9284
Taylor Made Body Art|5036 Vaughn Rd|Montgomery AL 36116|(334) 239-7434
Thicker Than Water|10099 Memorial Pkwy|SW Huntsville AL 35803|(256) 585-3693
Tight Cuts & Tattoos|1401 3rd Ave W # 103|Birmingham AL 35208|(205) 783-9244
Top Notch Tattoo|501 7th St|S Clanton AL 35045|(205) 755-7711
Total Illusion Tattoos|2000b S Wilson Dam Rd|Muscle Shoals AL 35661|(256) 248-4864
Toxxxic Ink Tattoos|619 Tuscaloosa St|Greensboro AL 36744|(334) 624-1212
Trillium Tattoo Studios|25814 Canal Rd|Orange Beach AL 36561|(251) 988-8282|Trilliumink.Com
Voodoo Needle|435 N Dean Rd|Auburn AL 36830|(334) 826-1195|Voodooneedle.Org
West Coast Tattoos|3115 Florence Blvd|Florence AL 35634|(256) 760-8011
Wicked Ways Tattoo|1022 20th St|S Birmingham AL 35205|(205) 983-7753
Wildman Tattoo|15 County Road 599|Hanceville AL 35077|(256) 339-7034
World Tattoo|Skyland Park|Mobile AL 36693|(251) 661-6605
Zen Tatu|28850 US Highway 98 # 107|Daphne AL 36526|(251) 626-0031
Zero Gravity|2601 Spring Ave|SW Decatur AL 35601|(256) 353-4461

now you can work on inserting this data into a database

Edited by QuickOldCar
Link to comment
https://forums.phpfreaks.com/topic/291198-breaking-down-curl/#findComment-1491764
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.