Results 1 to 3 of 3

Thread: str_replace puzzle

  1. #1
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    285
    Thanks
    95
    Thanked 3 Times in 3 Posts

    Default str_replace puzzle

    PHP Code:
    <?php
    $lastUpdate 
    date'j F Y'filemtime'pageContent/reviewActivity.txt' ) );
    $bigCount 0;
    echo 
    "<br /><br />";

    $bigData file_get_contents ("bigCollection");
    echo 
    $bigData;
    echo 
    "<br />Kilroy knocked!<br /><br />";

    echo 
    str_replace (" """$bigData);
    str_replace (" """$bigData);

    $lineItem explode ("*"$bigData);

    echo 
    "<br />Kilroy entered!<br /><br />";

    foreach (
    $lineItem as $item) {
        echo 
    "Item = " $item "<br />";
    }

    echo 
    "<br />Kilroy left!";
    ?>
    <br />
    <br />
    <a href="http://www.marainlaw.com/bottomline.php"><img border="2" src="images/marain-logo.gif" alt="***************" width="130" height="75" class="right" /></a>
    <br />
    <br />
    $bigData contains several sets of six two-digit numbers separated by spaces. Where that happens, I'm trying to use the str_replace function to convert them to a single twelve-digit number. When I echo the str_replace operation, all works as intended. But then when I attempt to actually do the replacement and explode the string, the original sequence is unchanged.

    The page in question is https://www.marainlaw.com/page.php?here=reviewActivity
    Last edited by marain; 02-10-2021 at 10:23 PM. Reason: Clarify, and correct typo; mark "resolved"

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,343
    Thanks
    99
    Thanked 111 Times in 109 Posts

    Default

    I have not looked too closely, but I notice that this one line does not do anything:

    Code:
    str_replace (" ", "", $bigData);
    It should be something like:

    Code:
    $bigData = str_replace (" ", "", $bigData);
    It would help to know what the results are that you are getting as opposed to what you are expecting as well as what what the contents of $bigData is/are.
    To choose the lesser of two evils is still to choose evil. My personal site

  3. The Following User Says Thank You to james438 For This Useful Post:

    marain (02-08-2021)

  4. #3
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    285
    Thanks
    95
    Thanked 3 Times in 3 Posts

    Default

    James,

    You hit the nail on its proverbial head. Thank you!

    Given your observation, I can now fix it easily. [URL]https://www.marainlaw.com/page.php?here=reviewActivity] shows the contents of $bigData, what I was expecting, and what I got. Well, when I make the correction you suggest, it will no longer show what I got.

Similar Threads

  1. Resolved str_replace Help!
    By X96 Web Design in forum PHP
    Replies: 2
    Last Post: 10-01-2009, 03:41 AM
  2. str_replace not giving correct output
    By jc_gmk in forum PHP
    Replies: 3
    Last Post: 08-14-2008, 05:16 PM
  3. Replies: 1
    Last Post: 05-21-2008, 01:09 PM
  4. mutiple str_replace?
    By lankinator in forum PHP
    Replies: 1
    Last Post: 07-21-2007, 11:21 AM
  5. Replies: 1
    Last Post: 06-28-2007, 04:31 PM

Bookmarks

Posting Permissions

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