SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict AbelaJohnB's Avatar
    Join Date
    Oct 2001
    Location
    Eureka, CA. USA
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding a block of text into a specific location of a file.

    Hello.


    I have a bock of text inside an existing varable.


    $text = "this is just a random block of text";


    Then I have another file:

    PHP Code:
    <html>
    <
    head>
    <
    title>Untitled Document</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <
    script><!-- The Scrolling Message Java Applet -------------------- 

    function 
    scroll_status (sval){ var msg "_INSERT_VARIABLE_TEXT_HERE"; var out " "; var 1; if (150 sval) ......setTimeout("scroll_status(150)",25); } }}// -- End of JavaScript code -------------- --></script>

    </head>

    <
    body bgcolor="#FFFFFF" onload="tmx1a=window.setTimeout('scroll_status(100)',50);" 


    Now, what I need is to add the block of text $text; into the above code where: _INSERT_VARIABLE_TEXT_HERE is.



    Can someone please advise me on how to accomplish this.


    Thank You.
    Last edited by AbelaJohnB; Mar 18, 2002 at 00:39.
    John B. Abela
    www.JohnAbela.Com

  2. #2
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'm probably misunderstanding you but wouldn't a plain echo work or if not you can use something like how templates work...

    this seems something you can easily do John so i'm fairly sure i'm on the wrong track here ... at least i could get you to clarify

  3. #3
    SitePoint Addict AbelaJohnB's Avatar
    Join Date
    Oct 2001
    Location
    Eureka, CA. USA
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello.


    I guess I did a terriable job explaining things....


    The first variable (the block of text) is being generated by a different file. (generate.php)

    So, this file (generate.php) has to somehow open the other file (footer.php - code listed above) and shove the variable (block of text) into the 'footer.php' file, at the specific place I indicated.


    Sorry, forgot to mention I was working with two seperate files, and one of them is a flat-file. (footer.php)



    Thanks.
    Last edited by AbelaJohnB; Mar 18, 2002 at 03:09.
    John B. Abela
    www.JohnAbela.Com

  4. #4
    SitePoint Member burchyk's Avatar
    Join Date
    Mar 2002
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there!

    I just thought, if your file you need to modify is a php-file, then just make an output of some variable in the right place, but first, prepend the initialization of that variable.
    Ex:

    PHP Code:
    <?
    $your_var
    ="something"//put it here
    ...
    ...
    ...
    print(
    "$your_var"); //output in the right place

    ?>
    I've meaned that inserting a line of text into a 2nd line of a file is easier then inserting a text into specific position

  5. #5
    SitePoint Addict AbelaJohnB's Avatar
    Join Date
    Oct 2001
    Location
    Eureka, CA. USA
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello.

    Ok, here is what I am trying to do.

    I have a file called: news.txt

    Code:
    <a name="newsitem1016416793,68681,"></a>
    Subject1:This is the text input for number one.<br><br>
    
    <a name="newsitem1016415492,28443,"></a>
    Subject2:This is the text input for number two.<br><br>
    
    <a name="newsitem1016337268,49011,"></a>
    Subject3:This is the text input for number three.<br>
    I need to do three things:


    1) REMVOE the entire line where <a name=XX></a> is


    2) Replace: SubjectX: WITH *news*


    3) Save it to a new file called: news_clean.txt



    Thank You.
    John B. Abela
    www.JohnAbela.Com

  6. #6
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi!

    PHP Code:
    <?php

    $test 
    '<a name="newsitem1016416793,68681,"></a>
    Subject1:This is the text input for number one.<br><br>
    <a name="newsitem1016415492,28443,"></a>
    Subject2:This is the text input for number two.<br><br>
    <a name="newsitem1016337268,49011,"></a>
    Subject3:This is the text input for number three.<br>'
    ;

    $test1 preg_replace("/<a[^>]*>(.*)<\/a>/siU"""$test);
    $test1 preg_replace("/Subject\d+/""*news*"$test);

    echo 
    $test1;

    $fp = @fopen("./news_clean.txt""w");
    flock($fpLOCK_EX);
    fwrite($fp$test1);
    flock($fpLOCK_UN);
    fclose($fp);
    ?>
    The first regexp removes the <a ... line and the second replaces subject with news

    And output will be:

    Code:
    *news*:This is the text input for number one.
    
    *news*:This is the text input for number two.
    
    *news*:This is the text input for number three.

  7. #7
    SitePoint Addict AbelaJohnB's Avatar
    Join Date
    Oct 2001
    Location
    Eureka, CA. USA
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Chris.


    Thanks for the code.


    However, it throws an error:

    PHP Code:
    WarningUnknown modifier 'a' in /home/xx/test.php on line 11 
    Line 11 is:

    PHP Code:
    $test1 preg_replace("/<a[^>]*>(.*)</a>/siU"""$test); 


    Any further ideas?
    John B. Abela
    www.JohnAbela.Com

  8. #8
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    Perth, Australia
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am sure Chris82's code would work - it just needs to escape the forward slash that closes the anchor tag, like this:

    PHP Code:
    $test1*=*preg_replace("/<a[^>]*>(.*)<\\/a>/siU",*"",*$test); 
    I know why his code didn't work - the same happened to my post - the back slash was eliminated, so it needs to be escaped itself. Hence the edit.
    Paul Davey
    webmaster for Whitford Church of Christ

  9. #9
    SitePoint Addict AbelaJohnB's Avatar
    Join Date
    Oct 2001
    Location
    Eureka, CA. USA
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, thanks guys !!!!
    John B. Abela
    www.JohnAbela.Com


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
  •