Super quick fix - adding a space

Discussion in 'PHP' started by Ithilnet, Aug 1, 2007.

  1. #1
    Hi.

    I have a little script. Basically it is a buzzcloud emulator.
    What it does:

    Input an URL and a keyword list. Example www.psp.com and a psp related keyword list. The script outputs:

    
    <a href="http://www.psp.com/psp+downloads">psp downloads</a><a href="http://www.psp.com/free+psp+downloads">free psp downloads</a><a href="http://www.psp.com/free+psp+game+downloads">free psp game downloads</a><a href="http://www.psp.com/psp+game+downloads">psp game downloads</a><a href="http://www.psp.com/psp+movie+downloads">psp movie downloads</a>
    
    Code (markup):
    This is the script:

    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <?php
    $url=$_GET['url'];
    $code = null;
    $filename = $_GET['txt'];   // the name of the txt file
    if ($url != null) {
        if (!$fp=fopen($filename,"r")) $code = $filename." not found.";   // if not found display a message
        else {
            while (!feof($fp)) {
            $buffer = trim(fgets($fp, 4096));
            $buffer_ad = strtr($buffer," ","+");
            $code .= "&lt;a href=\"" . $url . $buffer_ad."\"&gt;".$buffer."&lt;/a&gt;";
            }
            fclose ($fp);
        }
    }
    ?>
    <form action="buzzcloud.php" method="get">     <!-- LINE 25: change this line if you want to rename the source code file -->  <input name="url" type="text" /> url<br />
    <input name="txt" type="text" /> txt<br />
    <input type="submit" value="Generate" /><br />
    <textarea rows="15" cols="60" ><?php if ($code != null) echo $code; ?></textarea>
    </form>
    </body>
    </html>
    
    Code (markup):

    The problem:

    It outputs all keywords without any space between them. How do I change the script to add a space after every keyword?
     
    Ithilnet, Aug 1, 2007 IP
  2. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #2
    I guess you should change this line to
    
     $code .= "&lt;a href=\"" . $url . $buffer_ad."\"&gt;".$buffer."&lt;/a&gt;<br>";
    
    PHP:
    to make a linebreak between each line
     
    AsHinE, Aug 2, 2007 IP
  3. nagasharmi

    nagasharmi Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    echo 'Yes'."\r\n";

    This is "\r\n" is used to add space
    tryit
     
    nagasharmi, Aug 2, 2007 IP