+ Reply to Thread
Results 1 to 5 of 5

Thread: PHP Help (Searching array then delete if found)

  1. #1
    Chris S's Avatar
    Chris S is offline Retired Chris S is an unknown quantity at this point
    Join Date
    Mar 2005
    Posts
    1,036

    PHP Help (Searching array then delete if found)

    I have the following code to look through my iTunes Library and compile some data for me.

    PHP Code:
    <?php
    $function 
    $_GET['function'];

    $dbhost 'localhost';
    $dbusername 'sterling';
    $dbpasswd '******;
    $database_name = '
    music';

    $connection = mysql_pconnect("$dbhost","$dbusername","$dbpasswd")
        or die ("Couldn'
    t connect to server.");

    $db = mysql_select_db("$database_name", $connection)
        or die("
    Couldn't select database.");



    $url1 = '
    http://localhost';
    $url2 'music';
    $main_url $url1.'/'.$url2;

    $banned_urls = array("$url1""$main_url""$main_url.'/?C=D;O=A'""$main_url.'/?C=M;O=A'""$main_url.'/?C=S;O=A'""$main_url.'/?C=D;O=A'""$main_url.'/information.php'");

    $links GetInput("$main_url"'');

    function 
    GetInput($url) { 
       
    $handle=fopen($url'r');
       
    $contents '';
       while (!
    feof($handle)) {
          
    $contents .= fread($handle8192);
       }
       
    fclose($handle);
       return 
    $contents;


    function 
    GetLinks($url$filter
    {
        
    $links = array();
        
    $match_domain='_[hH][tT][tT][pP]:\/\/(.*?)(/|$)_';
        
    preg_match($match_domain$url$res); 
        
    $domain=$res[1]; 
        if (!
    $domain
            return 
    false
        if (!
    $input=GetInput($url)) 
            return 
    false
        
        
    $lookfor='/<[aA]\s.*?[hH][rR][eE][fF]=[             "\']{0,}([-.,\%_\(\)|=~;+:\?\&\/a-zA-Z0-9]+)[ "\'>]/';
        
    preg_match_all($lookfor$input$data);
        while (list(
    $k$v)=each($data[1]))
        {
            
    // filter by
            
    if( strlen($filter) )
            {
                if( !
    strstr($v$filter) )
                {
                    continue;
                }    
            }
            if (
    stristr($v'javascript:'))
            { 
                
    // ignore - contains javascript
            

            elseif (
    stristr($v'//')==$v
            { 
                
    $v='http:'.$v;
                
    $links[]=$v;
            } 
            elseif (
    stristr($v'http://')!=$v
            { 
                if (
    stristr($v'/')!=$v)
                    
    $sep='/';
                else
                    
    $sep='';
                
    $v='http://'.$domain.$sep.$v
                
    $links[]=$v;
            } 
            else
                
    $links[]=$v;
        }
        if( 
    count($links) )
        {
            
    $links=array_flip($links);
            
    $links=array_keys($links); 
        }
        else
            
    $links[] = 'No Data';
        return 
    $links


    if ((
    $function) == 'artists'){

    $artists GetLinks("$main_url"'');
    $numb_of_artists count($artists);

    $query mysql_query("UPDATE `information` SET artists='$numb_of_artists'") or die(mysql_error());


    if ((
    $query) == 'True'){
    echo 
    "Done. Also you have $numb_of_artists artists";
    }else{
    echo 
    "Whoops, there was an error but, you have $numb_of_artists artists";
    }

    }elseif ((
    $function) == 'albums'){

    $links GetInput("$main_url"'');
     
     
    $albums GetLinks("$main_url"'');


      foreach (
    $albums as $artist_album
       
    $search "%20";
       
    $replace " ";
     
    $albums preg_replace($search$replace$artist_album);
         
    $album_rar GetLinks($artist_album);
           
    $rar_count count($artist_rar);
         
    $count $count $raw_count;


    $query mysql_query("UPDATE `information` SET albums='$count'") or die(mysql_error());

    if ((
    $query) == 'True'){
    echo 
    "Done. Also you have $count albums";
    }else{
    echo 
    "Whoops, there was an error but, you have $count albums";
    }

    }elseif ((
    $function) == 'songs'){
    echo 
    "not coded yet";
    }else{
    ?>
    Please choose an option<br>
    <a href="information.php?function=artists">Artists</a>
    <p><a href="information.php?function=albums">Albums</a>
    <p><a href="information.php?function=songs">Songs</a>
    <?php
    }
    ?>
    Basically what I am trying to do is search $albums and see if there are some links in there. If there are (i know there will be) delete them. The one important thing is that I atleast get rid of the http://localhost because that will make it search the music directory over and over.

    Also, How do I remove %20 from the url. I tried

    PHP Code:
       $search "%20";
       
    $replace " ";
     
    $albums preg_replace($search$replace$artist_album); 
    but i get
    Code:
    Warning: preg_replace() [function.preg-replace]: No ending delimiter '%' found in G:\wamp\www\music\information.php on line 111
    and line 111 is the $abbums = preg_replace..... code.

    Anyways if you can help me with at least one of the problems that would be great.
    Last edited by Chris S; 02-18-2006 at 07:21 PM.

    I would love to change the world, but they won't give me the source code

  2. #2
    Chris S's Avatar
    Chris S is offline Retired Chris S is an unknown quantity at this point
    Join Date
    Mar 2005
    Posts
    1,036

    Re: PHP Help (Searching array then delete if found)

    i got it working

    I would love to change the world, but they won't give me the source code

  3. #3
    Bryon is online now Administrator Bryon has disabled reputation
    Join Date
    Apr 2005
    Location
    Northfield, NH
    Posts
    7,608

    Re: PHP Help (Searching array then delete if found)

    Str_replace().. Haha.

    I know you've been having problems with this for the last few days.. Is it finally working again?

  4. #4
    Jake's Avatar
    Jake is offline Developer Jake is an unknown quantity at this point
    Join Date
    Apr 2005
    Location
    Winona, MN
    Posts
    2,084

    Re: PHP Help (Searching array then delete if found)

    hehe why would you use preg_replace()...
    Jake Omann | Developer
    █ 888-X10-9668 - jake[@]x10hosting.com
    x10Hosting - Giving Away Hosting Since 2004
    Premium Hosting | VPS Services

  5. #5
    Chris S's Avatar
    Chris S is offline Retired Chris S is an unknown quantity at this point
    Join Date
    Mar 2005
    Posts
    1,036

    Re: PHP Help (Searching array then delete if found)

    anyways its working

    and quite sexy i might add.

    I would love to change the world, but they won't give me the source code

+ Reply to Thread

Similar Threads

  1. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  2. tons of PHP Resources
    By Chris S in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 01-16-2009, 10:07 AM
  3. [PHP] PHP For Starters
    By Complex in forum Tutorials
    Replies: 24
    Last Post: 06-14-2008, 11:40 PM
  4. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM
  5. Can some1 tell me if this is the legal IF 2.0?
    By pensoftware in forum Computers & Technology
    Replies: 9
    Last Post: 04-05-2006, 12:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers