Forum Moderators: coopster

Message Too Old, No Replies

reading 10 lines with php

         

armator

1:53 pm on Jun 12, 2005 (gmt 0)

10+ Year Member



Dear Mcibor

Sorry I am disturbing you again.
I need your kind helps.

Following code is working very good but I am wishing ,for example it must read from line 1 to line 10 .

I tried but I could not do it.

Could you please add your commands in this code?

Thanks again your kind helps.
Best Regards
armator

++++
CODE
++++++

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>

<style>
body {
background-color: #FFFFFF;
font-family: Arial, Verdana, sans-serif;
font-size: 0px;
color: #000000;
}

a { font-family: Arial, Verdana, sans-serif; font-size: 0px ; color: #ffffff; text-decoration: none}

a:hover { font-family: Arial, Verdana, sans-serif; font-size: 0px; color: #ffffff; background-color:#ffffff}

table { font-family: Arial, Verdana, sans-serif; font-size: 5px; color: #000000; margin-top: 0px; margin-right: 0px; margin-bottom: -50px; margin-left: -1px; padding-top: 0px; padding-right: 0px; padding-bottom: -20px; padding-left: 0px }

td { background-color: #ffffff; margin-top: 150px; }

.note { font-family: Arial, Verdana, sans-serif; font-size: 5px; color: #000000;
font-weight: bold;}
</style>

<div style ='position:absolute;top:-87px;bottom:300px;'</div>

<?
if (!$kategori_haber) $kategori_haber = array("haber");

$satir = file("http://www.domain.com/sdk.php") or die("Serverla ileti?im sa?lanamady!");

print "${'$yazi'}";
for ($x = 0; $x < sizeof($kategori_haber); $x++) {
for ($i = 0; $i < sizeof($satir); $i++) {
if (trim($satir[$i]) == "+$kategori_haber[$x]") {
$bas = $i;
break;

}
}

for ($i = $bas; $i < sizeof($satir); $i++) {
if (substr($satir[$i], 1, 1) == "+" ¦¦ $i == sizeof($satir) -1) {
$son = $i-17;
break;
}
}

for ($i = $bas; $i+1< $son; $i++) {

$yazi = trim($satir[$i]);
$yazi = ereg_replace ("sdk.php","http://www.domain.com/sdk.php",$yazi);
if ($yazi!= "-" &&!eregi("$kategori_haber[$x] Ön Sayfa", $yazi)) {
$yazi = str_replace("http://www.domain.com/sdk.php","http://www.domain.com/sdk.php", $yazi);
$haber_e = explode("¦", $yazi);
$haber_e = explode("table", $yazi);

echo "<font color=black> <b>&raquo; $haber_e[0] </b> </font>" ;

echo "<br>\n";}

}
}

?>

</html>

mcibor

2:09 pm on Jun 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Function file writes the file to an array of lines. So to read only ten lines modify the for loop:

if (!$kategori_haber) $kategori_haber = array("haber");

$satir = file("http://www.domain.com/sdk.php") or die("Serverla ileti?im sa?lanamady!");

print "${'$yazi'}";
for ($x = 0; $x < sizeof($kategori_haber); $x++) {
for ($i = 0; $i < 10; $i++) {
if (trim($satir[$i]) == "+$kategori_haber[$x]") {
$bas = $i;
break;

}

And that's it!

Best regards
Michal Cibor

PS. Use more www.php.net eg: file function is under [php.net...]

armator

2:26 pm on Jun 12, 2005 (gmt 0)

10+ Year Member



Dear Mcibor

Thanks your quick reply and kind helps.

I will try it now.

Best Regards
armator

armator

2:37 pm on Jun 12, 2005 (gmt 0)

10+ Year Member



Dear Mcibor

Sorry but it is reading all lines.

Thanks advance your kind help.

Best Regards
armator

mcibor

1:39 pm on Jun 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Change all sizeof($satir) to 10.

if (!$kategori_haber) $kategori_haber = array("haber");

$satir = file("http://www.domain.com/sdk.php") or die("Serverla ileti?im sa?lanamady!");

print "${'$yazi'}";
for ($x = 0; $x < sizeof($kategori_haber); $x++) {
for ($i = 0; $i < 10; $i++) {
if (trim($satir[$i]) == "+$kategori_haber[$x]") {
$bas = $i;
break;

}
}

for ($i = $bas; $i < 10; $i++) {
if (substr($satir[$i], 1, 1) == "+" ¦¦ $i == 10 -1) {
$son = $i-17;
break;
}
}

for ($i = $bas; $i+1< $son; $i++) {

$yazi = trim($satir[$i]);
$yazi = ereg_replace ("sdk.php","http://www.domain.com/sdk.php",$yazi);
if ($yazi!= "-" &&!eregi("$kategori_haber[$x] Ön Sayfa", $yazi)) {
$yazi = str_replace("http://www.domain.com/sdk.php","http://www.domain.com/sdk.php", $yazi);
$haber_e = explode("¦", $yazi);
$haber_e = explode("table", $yazi);

armator

2:09 pm on Jun 13, 2005 (gmt 0)

10+ Year Member



Dear Mcibor

Thanks again your kind helps.

Sorry it is giving error the reason of

if (substr($satir[$i], 1, 1) == "+" ¦¦ $i == 10 -1) {

and not reading .

Sorry I am disturbing you for this code and I check all functions by google but I could not find solution yet.

Best Regards
armator

mcibor

8:20 pm on Jun 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Change the 10 - 1 to 9, and it will be fine:

if (substr($satir[$i], 1, 1) == "+" ¦¦ $i == 9) {

Michal Cibor

armator

7:45 am on Jun 14, 2005 (gmt 0)

10+ Year Member



Dear Mcibor

Thank you very much your kind interest and helps.

It is working now as;

for ($i = $bas; $i < 145; $i++) {
if (substr($satir[$i], 1, 1) == "+" ¦¦ $i ==144) {

and I can play all lines if I wish.

Thanks again your kind helps.

Best Regards
armator