Forum Moderators: coopster

Message Too Old, No Replies

Php str_replace line limit

         

armator

8:19 am on Jul 10, 2005 (gmt 0)

10+ Year Member



Dear Mcibor

Sorry I am disturbing again.

I am connecting and getting all datas from meteorology address but I am wishing to get only 5 lines .
Forexample,this address has 500 lines and I am wishing
to get only 5 lines (from 385 to 390).
Could you please help me?
Which command I can add to following code?

Thanks advance your kind helps.
Brgds
armator

+++
code
+++

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

<html>
<head>

<title>Meteo</title>

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

$satir = file("http://www.domain.com/meteo.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 < 180; $i++) {
if (substr($satir[$i], 1, 1) == "+" ¦¦ $i ==179) {
$son = $i;
break;
}
}

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

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

$haber_e = explode("¦", $yazi);
$haber_e = explode("table", $yazi);

echo "<b>$haber_e[0]</b>" ;
echo "\n";}

}
}

?>

</html>

mincklerstraat

11:47 pm on Jul 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you could try:

$contents = file_get_contents('http://example.com/weather.html');
$array = explode("\n", $contents);
if(count($array) > 389){
for($i = 386; $i < 392; $i++){
echo $array[$i];
}
}

If this doesn't make sense, you might want to make a quick dive into the php manual to read up on what these functions do, and what the control structure for does - this really isn't a "fix it for me" forum as much as a "how would I do this can you help teach me" type of forum.

armator

12:30 pm on Jul 12, 2005 (gmt 0)

10+ Year Member



Dear mincklerstraat

Thanks your kind interest and helps.
I added your command and it is running now.

Kindly note this address contains xmlns.
Could you please tell me how I can change font sizes and how I can remove or disable border of this addres without css that I tried to change by str_replace but I could not.

Thanks advance your kind interest and helps.

Best Regards
armator

mincklerstraat

3:56 pm on Jul 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is difficult to answer since I don't know what it is you're getting (the 'input'). I'd suggest you ask this question in the html forum with some lines of the stuff you want to change if you don't know how to format it. Otherwise, just copy the page into a regular html file, and change it until it looks like you want it. Then look at the difference from the original, and figure out which str_replace rules to use (str_replace is pretty to use, I couldn't explain better than the manual does). If str_replace ends up being too simple, you'll have to use regular expressions, like preg_match and preg_replace. Once you have a really good idea of what needs to be changed into what, you can post back here for help with your regular expressions. You'll need to be pretty specific, though.

armator

4:03 pm on Jul 12, 2005 (gmt 0)

10+ Year Member



Dear mincklerstraat

Thanks your quick reply.

I will try it to solve problem.

I will inform to forum if I can not do.

Best Regards
armator