Web Analytics Made Easy -
StatCounter fopen and str_replace - CodingForum

Announcement

Collapse
No announcement yet.

fopen and str_replace

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • fopen and str_replace

    Hello all!

    Firstly i would like to apologise for the badly formed topic.

    filename: foo.php

    Code:
    <?php
    	$fd = fopen("index.php", "r"); 
    	$pagina = fread ($fd, filesize ("index.php"));
    	fclose($fd);
     
    	$bodytag = str_replace("%body%", "<% vlaggetje %>", "dit is tekst");
    
    print $bodytag;
    
         
    ?>
    in index.php i have "<% vlaggetje %>" I would like to replace that by "dit is tekst". What's wrong with my code?


    Thanks in advance

  • #2
    mixed str_replace ( mixed search, mixed replace, mixed subject [, int &count] )
    example:
    PHP Code:
    $string1 "abcabcabc";
    $string2 str_replace("abc""cba"$string1);
    echo 
    $string2//displays cbacbacba 

    Comment


    • #3
      there is a tag in the html code called: "<% vlaggetje %>" I needs to be repaced

      Comment


      • #4
        I need to change "< % replace me %>" into "some tekst"

        Code:
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Untitled Document</title>
        </head>
        <?php
        	$fd = fopen("foo.php", "r"); 
        	$pagina = fread ($fd, filesize ("foo.php"));
        	fclose($fd);
        
        	$bodytag = str_replace ("%body%", "blue", "<body text=%body%>");
        
        print $bodytag;
        
             
        ?>
        
        
        <body text=red>
        < % replace me %>
        </body>
        </html>

        Comment


        • #5
          not realy a great reader, huh?
          PHP Code:
          <?php
              $fd 
          fopen("index.php""r"); 
              
          $pagina fread ($fdfilesize ("index.php"));
              
          fclose($fd);
           
              
          $bodytag str_replace('<% vlaggetje %>''dit is tekst'$bodytag );

          print 
          $bodytag;
          ?>
          of course, you need to be sure that index.php is not more then 8192 bytes , because reading will stop at that point...
          Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

          Comment


          • #6
            did you test the code? It doesn't work here..

            Comment


            • #7
              Originally posted by arvind View Post
              did you test the code? It doesn't work here..
              no i did not test it. i don't have to since i know that the line i added is correct.

              i was also responding to your initial code, and i don't realy see where $bodytag is set so i can't realy help you with that.

              the new code you posted doesn't make any sense to me. what exactly are you truing to do? have pag1.php read in page2.php and then replace a tag in page2.php?
              Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

              Comment

              Working...
              X