Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Multiline string problem

    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!

    PHP Code:
    <?php
    $c
    ="";
    $openurl="http://cnn.com";
    $file fopen($openurl,"r");
    while(!
    feof($file))  $c .= fgets($file1024);
    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;
    ?>

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    New Coder
    Join Date
    Jul 2007
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post

    PHP Code:

    <meta name="Description" content="CNN.com delivers the latest breaking news and information on the latest top stories, weather, business, entertainment'; 
    Should be:
    PHP Code:
    <meta name="Description" content="CNN.com delivers the latest breaking news and information on the latest top stories, weather, business, entertainment">; 
    replace your '; with ">';
    Last edited by phpandmysql; 07-05-2007 at 06:56 PM.
    PHP and MYSQL
    $string = "3Ip*hKEpanKI#8dmUys&*KqlIJ*P8D";
    $new_string = ereg_replace("[^a-z]", "", $string);
    echo "<a href=http://www.$new_string.org>$new_string</a>";

  • #4
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the replies guys ...

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

    PHP Code:
    <?php
    $c
    ="";
    $openurl="http://cnn.com";
    $file fopen($openurl,"r");
    while(!
    feof($file))  $c .= fgets($file1024);
    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.

  • #5
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Have done some further poking around.. consider the code
    PHP Code:
    <?php
    $c
    ="";
    $openurl="http://cnn.com";
    $file fopen($openurl,"r");
    while(!
    feof($file))  $c .= fgets($file1024);
    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:
    Code:
    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
    Code:
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •