Jump to content

A problem with strpos and strings that span multiple lines


dmulyava

Recommended Posts

Hi folks ...

 

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;
?>

 

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.