Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    PHP cURL - preg_match_all

    Hi,

    I am trying to get from the link which is XML some text to convert into link or drop down list. But somehow it will not work

    PHP Code:
     $curl curl_init();
        
    curl_setopt ($curlCURLOPT_URL"http://itunes.com/version?touchUpdate=true");
        
    curl_setopt($curlCURLOPT_RETURNTRANSFER1);

        
    $result curl_exec ($curl);
        
    curl_close ($curl);

        
    //links
        
    if(preg_match_all("~(.*)/iPhone/(.*)4\.0(.*)Restore"$result$links))
        {
            foreach(
    $links[0] as $link)
            {
                echo 
    $link."<br />";    
            }
        } 

    The XML Source File shows this

    Code:
    <key>iPhone2,1</key>
    					<dict>
    						<key>7A341</key>
    						<dict>
    							<key>OfferPartialRestoreAsUpdate</key>
    							<true/>
    							<key>Restore</key>
    							<dict>
    								<key>BuildVersion</key>
    								<string>7E18</string>
    								<key>DocumentationURL</key>
    								<string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-7822.20100202.VfP8u/iPhoneDocumentation_3.1.3.ipd</string>
    								<key>FirmwareURL</key>
    								<string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-7472.20100202.8tugj/iPhone2,1_3.1.3_7E18_Restore.ipsw</string>
    								<key>ProductVersion</key>
    								<string>3.1.3</string>
    							</dict>
    						</dict>
    						<key>7A400</key>
    						<dict>
    							<key>SameAs</key>
    							<string>7A341</string>
    						</dict>
    						<key>7C106c</key>
    						<dict>
    							<key>SameAs</key>
    							<string>7A341</string>
    						</dict>
    						<key>7C116a</key>
    						<dict>
    							<key>SameAs</key>
    							<string>7A341</string>
    						</dict>
    						<key>7C144</key>
    						<dict>
    							<key>SameAs</key>
    							<string>7A341</string>
    						</dict>
    						<key>7D11</key>
    						<dict>
    							<key>SameAs</key>
    							<string>7A341</string>
    						</dict>
    						<key>7E18</key>
    						<dict>
    							<key>Restore</key>
    							<dict>
    								<key>BuildVersion</key>
    								<string>7E18</string>
    								<key>DocumentationURL</key>
    								<string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-7822.20100202.VfP8u/iPhoneDocumentation_3.1.3.ipd</string>
    								<key>FirmwareURL</key>
    								<string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-7472.20100202.8tugj/iPhone2,1_3.1.3_7E18_Restore.ipsw</string>
    								<key>ProductVersion</key>
    								<string>3.1.3</string>
    							</dict>
    						</dict>
    						<key>Unknown</key>
    						<dict>
    							<key>Universal</key>
    							<dict>
    								<key>Restore</key>
    								<dict>
    									<key>BuildVersion</key>
    									<string>7E18</string>
    									<key>DocumentationURL</key>
    									<string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-7822.20100202.VfP8u/iPhoneDocumentation_3.1.3.ipd</string>
    									<key>FirmwareURL</key>
    									<string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-7472.20100202.8tugj/iPhone2,1_3.1.3_7E18_Restore.ipsw</string>
    									<key>ProductVersion</key>
    									<string>3.1.3</string>
    									<key>EpochVersion</key>
    									<string>2</string>
    								</dict>
    							</dict>
    						</dict>
    					</dict>

    The Text i want to get is

    Code:
    <key>iPhone2,1</key>
    and

    Code:
    <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-7472.20100202.8tugj/iPhone2,1_3.1.3_7E18_Restore.ipsw</string>

    New some advice how i can do that.. Thanks

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Since you captured an XML string why not just use an XML library to parse it. Take $result and load it into SimpleXML and then you can use the structure that the SimpleXML library creates to grab anything you need from the XML data.

    http://us.php.net/manual/en/function...oad-string.php

    And you can also use DOM in much the same way.
    http://us.php.net/manual/en/domdocument.loadxml.php
    Last edited by Spookster; 01-13-2012 at 06:35 AM.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • Users who have thanked Spookster for this post:

    karabey (01-13-2012)

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for your reply but i am newbie at PHP.. What i could do is without your tips.


    PHP Code:
    $url "http://itunes.com/version?touchUpdate=true";
    $page_all file_get_contents($url); 

    preg_match_all('~http://(.*)/iP(.*)Restore.ipsw~'$page_all$div_arrayPREG_PATTERN_ORDER);

    echo 
    "<pre>";
    print_r($div_array[0]);
    echo 
    "</pre>"

    This extract the needed files but it doesn't filter same Texts.

    Otherwise i have a Code that converts Text to Link and does only one Link.. Rest is not shown.

    PHP Code:
        <?php
        
                
            $content 
    file_get_contents('http://itunes.com/version?touchUpdate=true');
            
            
    $matches "~(.*)/iP(.*)Restore~";
            
        
            if(
    preg_match($matches$content$url)) {    
                
                        
            echo 
    preg_replace($matches'<a href="'.$url[0].'" rel="nofollow">'.$url[0].'</a>'$matches);
            
            }
        
            
        
    ?>

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    What you are doing is way more complicated. Use my suggestion and use and XML library. Would only take a few lines of code to accomplish.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    As i have followed the Manuals you gave me, i could not find how to read the target.

    Example

    PHP Code:
    <?php

    $xml 
    simplexml_load_file('http://itunes.com/version?touchUpdate=true'); 

    ?>
    Sorry i am newbie and have to read so much.. It takes time

  • #6
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    You would use your existing cURL code to grab the feed because you told it to return a string containing the XML data.

    This should give you the XML data in a SimpleXML structure. Then you can just grab the value of the node that you want using that structure syntax.
    PHP Code:
    $result curl_exec ($curl); 
    $xml simplexml_load_string($result);
    var_dump($xml); 
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #7
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok most is done


    PHP Code:
    <?php


    $URL 
    "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStore.woa/wa/com.apple.jingle.appserver.client.MZITunesClientCheck/version/?touchUpdate=true";


    $ch curl_init();


    curl_setopt($chCURLOPT_URL$URL); 
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    curl_setopt($chCURLOPT_HTTPAUTHCURLAUTH_BASIC);
    curl_setopt($chCURLOPT_HEADER0);


    $content curl_exec($ch);

    $result curl_getinfo($ch);

    $reg_exUrl "~(.*)/iP(.*)Restore.ipsw~";

    if(
    preg_match_all($reg_exUrl$content$resultPREG_PATTERN_ORDER));
        {
            foreach(
    $result[0] as $link)
            {
                echo 
    preg_replace($reg_exUrl'<a href="'.$link.'">'.$link.'</a><br />'$link);   
            }
        }
    curl_close($ch);
    ?>
    While the Source has same Text more than one it shows again.. Is there a way to show only one instead to repeat the same.

    Result of Code
    Code:
    http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-5863.20090127.rt56K/iPod2,1_2.2.1_5H11a_Restore.ipsw
    http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-5863.20090127.rt56K/iPod2,1_2.2.1_5H11a_Restore.ipsw
    http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-5863.20090127.rt56K/iPod2,1_2.2.1_5H11a_Restore.ipsw
    http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-7481.20100202.4orot/iPhone1,1_3.1.3_7E18_Restore.ipsw
    http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-7481.20100202.4orot/iPhone1,1_3.1.3_7E18_Restore.ipsw
    http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-7481.20100202.4orot/iPhone1,1_3.1.3_7E18_Restore.ipsw
    http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-7481.20100202.4orot/iPhone1,1_3.1.3_7E18_Restore.ipsw
    http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-7468.20100202.pbnrt/iPhone1,2_3.1.3_7E18_Restore.ipsw
    http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-7468.20100202.pbnrt/iPhone1,2_3.1.3_7E18_Restore.ipsw
    http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-7468.20100202.pbnrt/iPhone1,2_3.1.3_7E18_Restore.ipsw
    http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-7472.20100202.8tugj/iPhone2,1_3.1.3_7E18_Restore.ipsw
    http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-7472.20100202.8tugj/iPhone2,1_3.1.3_7E18_Restore.ipsw
    http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-7472.20100202.8tugj/iPhone2,1_3.1.3_7E18_Restore.ipsw
    Links are show like this

    <a href=" <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw"> <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw</a><br /><a href=" <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw"> <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw</a><br /><a href=" <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw"> <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw</a><br /><a href=" <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw"> <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw</a><br /><a href=" <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw"> <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw</a><br /><a href=" <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw"> <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw</a><br /><a href=" <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw"> <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw</a><br /><a href=" <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw"> <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw</a><br /><a href=" <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw"> <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw</a><br /><a href=" <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw"> <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw</a><br /><a href=" <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw"> <string>http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-4313.20080226.Sw39i/iPhone1,1_1.1.4_4A102_Restore.ipsw</a><br />
    Last edited by karabey; 01-14-2012 at 02:48 AM. Reason: script update

  • #8
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    I'm done helping you. I've done everything but completely write the code for you and you still keep going down the path of making it way over complicated.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •