...

View Full Version : PHP Multiline string problem



dmulyava
07-05-2007, 07:01 PM
Hi experts..

I suspect that this will be a trivial question to the experts here, and you will be able to help me out.

I have been using a shared hosting account while developing my script, and now I have to move it to the production server.

One thing I realized, though, is that the test server was using PHP 4.4.6, and the new (production) server is using 4.3.9; There is something different between these two versions, or between the php_ini variables, that is throwing off how my scripts are using multiline strings.

Here is an example. Consider the following code. It opens an external website, reads it's contents into a variable. It then scans the variable for a string, and outputs it's location. On the test server - this page outputs 215. On the new server, nothing is echoed.. meaning that it did not find the string.

What should I be looking into? Thanks a big bunch! :thumbsup:



<?php
$c="";
$openurl="http://cnn.com";
$file = fopen($openurl,"r");
while(!feof($file)) $c .= fgets($file, 1024);
fclose($file);



$findme1 = '<meta http-equiv="refresh" content="1800">
<meta name="Description" content="CNN.com delivers the latest breaking news and information on the latest top stories, weather, business, entertainment';
$pos1 = strpos($c, $findme1);
echo $pos1;
?>

CFMaBiSmAd
07-05-2007, 07:20 PM
Check your web server log for errors or turn on full PHP error_reporting or add some error checking and error reporting to the function calls in your code. It is likely that the fopen(...) function call is failing because of something like allow_url_fopen not being enabled.

phpandmysql
07-05-2007, 07:52 PM
<meta name="Description" content="CNN.com delivers the latest breaking news and information on the latest top stories, weather, business, entertainment';



Should be:


<meta name="Description" content="CNN.com delivers the latest breaking news and information on the latest top stories, weather, business, entertainment">';


replace your '; with ">';

dmulyava
07-05-2007, 07:56 PM
Thanks for the replies guys ...

fopen works.. in fact, the following code produces the same results on both servers


<?php
$c="";
$openurl="http://cnn.com";
$file = fopen($openurl,"r");
while(!feof($file)) $c .= fgets($file, 1024);
fclose($file);



$findme1 = '<meta name="Description" content="CNN.com delivers the latest breaking news and information on the latest top stories, weather, business, entertainment';
$pos1 = strpos($c, $findme1);
echo $pos1;
?>

It's got something to do with multiline strings. phpandmysql - thanks for the suggestion, but the findme variable simply looks for that string in the HTML - it does not matter if the tags it contains are properly closed.

dmulyava
07-05-2007, 10:28 PM
Have done some further poking around.. consider the code
<?php
$c="";
$openurl="http://cnn.com";
$file = fopen($openurl,"r");
while(!feof($file)) $c .= fgets($file, 1024);
fclose($file);

$findme1 = '<meta http-equiv="refresh" content="1800"><br>
<meta name="Description" content="CNN.com delivers the latest breaking news and information on the latest top stories, weather, business, entertainment, politics, and more. For in-depth coverage, CNN';
echo strrev($findme1);







?>

This code outputs the reverse of the string. The result? The "working" server returns:

NNC ,egarevoc htped-ni roF .erom dna ,scitilop ,tnemniatretne ,ssenisub ,rehtaew ,seirots pot tsetal eht no noitamrofni dna swen gnikaerb tsetal eht sreviled moc.NNC"=tnetnoc "noitpircseD"=eman atem<
>rb<>"0081"=tnetnoc "hserfer"=viuqe-ptth atem<

The nonworking server returns

NNC ,egarevoc htped-ni roF .erom dna ,scitilop ,tnemniatretne ,ssenisub ,rehtaew ,seirots pot tsetal eht no noitamrofni dna swen gnikaerb tsetal eht sreviled moc.NNC"=tnetnoc "noitpircseD"=eman atem<

>rb<>"0081"=tnetnoc "hserfer"=viuqe-ptth atem<

A blank line between the two lines!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum