Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2003
    Miami, FL

    String Replacement in Text Box?


    I'm trying to figure out the best way to go about this. I've recently developed a mailing list program. I'd like to be able to have the ability to enter a string, such as %fname% and when it gets submitted, have the script convert %fname% with the variables $fname from a MySQL Row and then insert it into the mail message and email it. Im not sure exactly how to go about it.

    I believe I have to use str_replace, but I'm not exactly sure how to do it with MySQL Rows.

    I've searched and searched and am unable to find anything to what I need?

  2. #2
    This is how I do it. I have a file called mailingtemplate.html, which is a regular html file with 3 variables in it: @@@date, @@@message, and @@@remove
    PHP Code:
        $message=nl2br($_REQUEST["message"]); //get submitted message and change newlines to <br>
    $fp="mailingtemplate.html"// open mailingtemplate.html
    $text fread($ffilesize($fp));
    $text=str_replace("@@@message",$message,$text); // replace message variable in file by typed message
    $text=str_replace("@@@remove",$remove,$text); // replace remove link
    $today date("d-m-Y H:i");
    $text=str_replace("@@@date",$today,$tekst); // replace date variable 
    after that, just mail() the message

    hope this is what you're looking for

  3. #3
    Join Date
    Jul 2003
    A different approach to the above :

    PHP Code:
    $contents implode("",file("somefile.txt"));

    // What we are looking for (your keys)
    $search = array("%fname%","%lname%");

    /* -- insert your mysql connection, query code here */

    while($row mysql_fetch_assoc($result))
    // What we will replace them with (must be
        // in the same order as the keys above)

    $replace = array($row['fname'],$row['lname']);

    // Do the search + replace
    $contents str_replace($search,$replace,$contents);
    // Email
    mail("[email protected]","email",$contents);

    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

Posting Permissions

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