myspace site

Discussion in 'PHP' started by xxsAm, May 13, 2007.

  1. #1
    xxsAm, May 13, 2007 IP
  2. Subikar

    Subikar Active Member

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #2
    How much time it take to complete this website. Why you are not using wiki.
    Use PMWIKI it is easy to use and there is password protection option for every page.
     
    Subikar, May 13, 2007 IP
  3. xxsAm

    xxsAm Active Member

    Messages:
    464
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Not sure how long i spent total. Probably 60+ hours. Alot of the content is custom made by me(contact tables). I'll look into the pmwiki that u mentioned. Thanks.
     
    xxsAm, May 14, 2007 IP
  4. Rub3X

    Rub3X Well-Known Member

    Messages:
    1,902
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    135
    #4
    You can use wordpress. Instead of having posts on the main page you can have all the categories. Each time you add a contact table just make it in the sports category etc.
     
    Rub3X, May 14, 2007 IP
  5. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #5
    
    <?php
    function page_name_exists( $name )
    {
     	global $pages ;
     	
     	$ret = false ;
     	
    	$name = str_replace( "-", " ", urldecode( $name ) );
    	
    	foreach( $pages as $k => $v )
    	{
    		if( $v['name'] == trim( $name ) )
    		$ret = true ;	
    	}
    	return $ret ;
    }
    function id_by_name( $name )
    {
    	global $pages ;
     	
     	$name = str_replace( "-", " ", urldecode( $name ) );
     	
    	foreach( $pages as $k => $v )
    	{
    		if( $v['name'] == $name )
    		{
    			return $k;
    		}	
    	}
    }
    
    $started = microtime( );
    
    if( !( $data = @file_get_contents( 'http://www.layoutsmart.com/musicandbands.php' ) ) )
    {
    	die("Error 001 : Please try later");
    }
    elseif( !preg_match_all('/<table width="527" border="0" cellpadding="0" cellspacing="0">(.*?)<\/table>/si', $data, $tables ) )
    {
    	die("Error 002 : Please try later" );
    }
    elseif( !$tables[1] )
    {
    	die("Error 003 : Please try later" );	
    }
    else
    {
    	foreach( $tables[1] as $count => $table )
    	{
    	 	if( $table != "" )
    	 	{
    			preg_match( '~(<img src="(.*?)" alt="(.*?)" width="300" height="150" />)~', $table, $img );
    			preg_match( '/<textarea(.*?)<\/textarea>/si', $table, $tarea );
    			$pages[$count + 1]["name"] = trim( $img[3] );
    			$pages[$count + 1]["img"] = trim( $img[2] );
    			$pages[$count + 1]["tarea"] = trim( $tarea[0] ) ;	
    		}
    	}
    }
    if( @$_GET['page'] and !$_GET['name'] )
    {
    	$selectby = 'page';
    }
    elseif( $_GET['name'] and !$_GET['page'] )
    {
    	$selectby = 'name';
    }
    else
    {
    	$selectby = 'page';
    }
    if( $selectby == 'page' and !array_key_exists( $_GET['page'], $pages  ) )
    {
    	die("Error 004 : Page out of range");
    }
    elseif( $selectby == 'name' and !page_name_exists( $_GET['name'] ) )
    {
    	die("Error 005 : Page not found");	
    }
    else
    {
    	switch( $selectby )
    	{
    		case 'name':
    			$page = $pages[ id_by_name( $_GET['name'] ) ];
    		break;
    		
    		case 'page':
    			$page = $pages[ $_GET['page'] ];
    		break;
    	}
    }
    ?>
    <h2>This is where I stop, html is boring</h2>
    Parsed <?=count( $pages ) ?> pages in <?=round( microtime( ) - $start, 5 ) ?> seconds <br />
    Page name : <?=$page['name']; ?><br />
    Page image : <?=$page['img']; ?><br />
    Page textarea : <?=$page['tarea']; ?><br />
    PHP:
    Example : page.php?name=Zao
    Example : page.php?page=1
    Example : page.php?name=As-I-Lay-Dying ( for seo friendly links )

    where name is the name of the band ( I assume ) OR page is the number of the page, currently 122 pages, parsed in about 2 seconds, if you use it post a link and I'll do the rewrite for it too ....

    I don't really know if this is a good idea, just bored I suppose ......
     
    krakjoe, May 14, 2007 IP
    Rub3X likes this.
  6. Rub3X

    Rub3X Well-Known Member

    Messages:
    1,902
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    135
    #6
    Wow nice code man, major reps added :)
     
    Rub3X, May 14, 2007 IP
  7. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #7
    I just changed it a lil bit, I forgot to urldecode the names ( dunno if you'll need to, is good practice though ), and made it so names with spaces in can have -'s in thier place and still work ..... and thanks :)
     
    krakjoe, May 14, 2007 IP
  8. Rub3X

    Rub3X Well-Known Member

    Messages:
    1,902
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    135
    #8
    Hey I'm helping him make this.

    Can you please make that whole code in to a loop which on each loop inserts all of that data into a mysql DB? The back bend for the script is going to be SQl. The code to display it from the DB is already done. Was just looking for a quick way to scrape the data and add it to a DB. You don't need to type the SQL statement, just put the variables there and a comment so I know where to put it. Thanks, and if you can't do it I'll try and mod your code a bit :)
     
    Rub3X, May 14, 2007 IP
  9. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #9
    
    <?php
    if( !( $data = @file_get_contents( 'http://www.layoutsmart.com/musicandbands.php' ) ) )
    {
    	die("Error 001 : Please try later");
    }
    elseif( !preg_match_all('/<table width="527" border="0" cellpadding="0" cellspacing="0">(.*?)<\/table>/si', $data, $tables ) )
    {
    	die("Error 002 : Please try later" );
    }
    elseif( !$tables[1] )
    {
    	die("Error 003 : Please try later" );	
    }
    else
    {
    	foreach( $tables[1] as $count => $table )
    	{
    	 	if( $table != "" )
    	 	{
    			preg_match( '~(<img src="(.*?)" alt="(.*?)" width="300" height="150" />)~', $table, $img );
    			preg_match( '/<textarea(.*?)<\/textarea>/si', $table, $tarea );
    			$pages[$count + 1]["name"] = trim( $img[3] );
    			$pages[$count + 1]["img"] = trim( $img[2] );
    			$pages[$count + 1]["tarea"] = trim( $tarea[0] ) ;	
    		}
    	}
    }
    if( !mysql_connect( 'localhost', 'username', 'password' ) )
    	die(mysql_error( ));
    elseif(!mysql_select_db( 'database' )) 
    	die(mysql_error( ));
    else
    {
    	foreach( $pages as $num => $data )
    	{
    		@extract( $data );
    		if( !mysql_query( "INSERT INTO `table` VALUES('$num', '$name', '$img', '$tarea')" ) )
    			die( mysql_error( ) );
    	}
    }
    
    
    ?>
    
    
    PHP:
    something like that, you might wanna addslashes before you insert the data
     
    krakjoe, May 14, 2007 IP
  10. Rub3X

    Rub3X Well-Known Member

    Messages:
    1,902
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    135
    #10
    Worked flawlessly, can you add me to MSN? th3rub3x [ @ ] Gmail.com, that is if you'd like to do a project for money.
     
    Rub3X, May 14, 2007 IP
  11. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #11
    At the moment I can't work, my mum is real ill and I'm staying in the hospital with her, just using internet cafes every few days to take my mind off, I should be home sometime this week hopefully, my msn is

    I will certainly need the cash when I get home though, thanks :)
     
    krakjoe, May 14, 2007 IP
  12. Rub3X

    Rub3X Well-Known Member

    Messages:
    1,902
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    135
    #12
    Sorry to hear that :(. Added to MSN.
     
    Rub3X, May 14, 2007 IP
  13. Rub3X

    Rub3X Well-Known Member

    Messages:
    1,902
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    135
    #13
    Hmm for some reason that code is only parsing the music area. Any other section it just gets all the wrong data.
     
    Rub3X, May 14, 2007 IP
  14. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #14
    I only parsed the page posted, post the others, or send me them in an email and next time I get to a pc I'll have a go, gotta go, back in a few hours probably....
     
    krakjoe, May 14, 2007 IP
  15. Rub3X

    Rub3X Well-Known Member

    Messages:
    1,902
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    135
    #15
    Rub3X, May 14, 2007 IP
  16. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #16
    its coz the alt attribute of img tags in 1st example posted held the title and the others dont, on mobile phone right now, I'll do it later, it's dooable still, maybe someone else will have a go before I get back to a pc
     
    krakjoe, May 14, 2007 IP