x10Hosting Forums

Corporate Free Hosting for the Masses.



Register

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
x10 Sophmore

nahsorhseda's Avatar

Join Date: Oct 2007
Posts: 115
Credits: 1,011
nahsorhseda is on a distinguished road
Location: mumbai

Quote  
06-20-2008, 03:04 AM
parsing html links with php [100 credits]

i have a html page for ex:

HTML Code:
..........<body>
<a href="jj5f.txt">rtt</a><br>
<a href="jjf75.txt">rtt</a><br>
<a href="jjof.txt">rtt</a><br>

<a href="jj8f.txt">rtt</a><br>
</body>............
so ill then open that page
PHP Code:
$content=fopen('page.html'); 
from $content i want to find out the links ending only with .txt and echo them as
PHP Code:
<a href="mydomain.com/folder/jj8f.txt">rtt</a
ill pay 100 credits for this
__________________
help with php/c
jokes world
Reply With Quote
nahsorhseda is offlineReport Post
x10 Elder

VPmase's Avatar

Join Date: Nov 2007
Posts: 831
Credits: 17,375
VPmase will become famous soon enough
Location: Dixon, IL, USA

Send a message via MSN to VPmase
Quote  
06-20-2008, 01:12 PM
Re: parsing html links with php [100 credits]

1) Why would you fopen an HTML page?
2) Why don't you just add the links to the php page manually?
__________________
Visit my site!
Always use the search function before posting a new thread!
Extra10 | BuxBank | NeoBux

Extra10 | BuxBank | NeoBux
Help me out <3
Helpful suggestions: Read the rules on every forum, follow said rules, and if you are unsure or need help, search first
Reply With Quote
VPmase is offlineReport Post
x10Hosting Member

Join Date: Jun 2008
Posts: 9
Credits: 298
sadm1r is on a distinguished road
Quote  
06-20-2008, 01:33 PM
Re: parsing html links with php [100 credits]

hi there.
i didn't quit understood what you aimed at, and am in kinda hurry ( my pizza is cooling down :D).
if i got it well, you have one file named e.g. "site.html" and you want to take text links from that file and have it displayed on your other web page.
i've just made some small code, it might need some tweaks because it can be possibly buggy.
so let me explain what it does.
it opens your file named 'site.html'.
then it takes line by line and check it... if line contains parts of string (all 3 required in what i made) "a href" && ".txt" && "</a>", it displays the line.
Code:
<?php
echo "links ending with .txt extension:<br>";
$file = fopen('site.html',"r");
$str = array("a href", ".txt", "</a>");
while(!feof($file))
{
	$line = fgets($file);
	$i=0;
	do{
		$check = strpos($line,$str[$i]);
		if($i==2 && $check)
		{
			echo $line;
		}
		$i++;
	}while($check && $i<3);
}
fclose($file);
?>
this might have some problems if your anchor passes into the next line. or you-name-what situation that can occur (e.g. link that contains .txt as part of it, but isnt text file etc).
but i guess it should work well for what you asked )))
gl i hope it helped d(^_^)b

Last edited by sadm1r; 06-20-2008 at 01:34 PM.
Reply With Quote
sadm1r is offlineReport Post
x10 Lieutenant

leafypiggy's Avatar

Join Date: Aug 2007
Posts: 399
Credits: 4,077
leafypiggy is on a distinguished road
Location: Massachusetts

Send a message via AIM to leafypiggy Send a message via MSN to leafypiggy
Quote  
06-20-2008, 01:40 PM
Re: parsing html links with php [100 credits]

please explain what you need better. we cant do somthing for you if you dont help us understand
__________________
[15:07] * infoinn was kicked by Brandon (brandon@in.da.hood) Reason (Please don't compare Dedicated Servers with Labtops, there totally different.)

[12:00] * Neil sets mode +hIv on NotWithLife #offtopic (HAHA, you have the aids!)
Reply With Quote
leafypiggy is offlineReport Post
x10Hosting Member

Join Date: Jun 2008
Posts: 9
Credits: 298
sadm1r is on a distinguished road
Quote  
06-20-2008, 02:29 PM
Re: parsing html links with php [100 credits]

Quote:
Originally Posted by leafypiggy View Post
please explain what you need better. we cant do somthing for you if you dont help us understand
i think his situation is:
he has one page where his links are posted (or where he adds the links manually). he wants certain data (links to text files) to be visible from the other web page as well.

my guess is that he wants txt files posted on other pages as well once he adds them on other site, and he wants to solve it with by some code so that he doesn't have to alter several pages once he adds up some info somewhere on one page.

e.g. like when you make a database, and want to use reference key so that you don't have to alter data each time in several tables.

Last edited by sadm1r; 06-20-2008 at 02:30 PM.
Reply With Quote
sadm1r is offlineReport Post
x10 Sophmore

nahsorhseda's Avatar

Join Date: Oct 2007
Posts: 115
Credits: 1,011
nahsorhseda is on a distinguished road
Location: mumbai

Quote  
06-21-2008, 05:43 AM
Re: parsing html links with php [100 credits]

iam opening a remote file using curl to do this and hence i cant use fgets
i tried some html parsers but they only parse link such as "<a href="http://xyz.com/www.txt">grg</a> but not "<a href="xyz.txt">grg</a>"
here is the code iam using

PHP Code:
<?

if (function_exists('curl_init')) 
{
  
   
$ch curl_init();

   
curl_setopt($chCURLOPT_URL'http://xyz.xom/site.html');

   
   
curl_setopt($chCURLOPT_HEADER0);

  
   
curl_setopt($chCURLOPT_RETURNTRANSFER1);

  
   
curl_setopt($chCURLOPT_USERAGENT'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0');

   
$content curl_exec($ch);
//echo"$content";

   
curl_close($ch);
} else {
 echo
" error while connecting";
}
?>
__________________
help with php/c
jokes world
Reply With Quote
nahsorhseda is offlineReport Post
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[PHP] PHP For Starters Complex Tutorials 24 06-15-2008 12:40 AM
PHP not parsing. techcrew206 Free Hosting 2 04-20-2008 04:08 PM
tons of PHP Resources Chris S Scripts & 3rd Party Apps 8 09-29-2007 09:09 PM
Links to Many Many Resources! Superpoo Scripts & 3rd Party Apps 18 03-29-2005 07:22 AM
PHP or HTML? xAdReNaLiNx Free Hosting 3 02-17-2005 08:07 PM


All times are GMT -5. The time now is 12:21 PM. Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0 RC7
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

Personal Car Finance | Loans | Car salvage | Personal Loans | Property in Spain