Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Re: ereg_replace

    > $linked_comments = ereg_replace("\n","<br>",$linked_comments");

    Try:

    $linked_comments = str_replace("\r\n","\n",$linked_comments");
    $linked_comments = str_replace("\n","<br>",$linked_comments");

    If you do not use regular expression for replacement, than
    use str_replace instead of ereg_replace, wchich requires
    esapeing spesial chars (I believe than newline char is special
    char in regexp).

    Hilarion


    Hilarion Guest

  2. Similar Questions and Discussions

    1. Daft ereg_replace() question.....
      I thought this would be easy, but have wasted the best part of 2 hrs trying to make it work I have a string: $string = "!!shocking.jpg"; I...
    2. ereg_replace at PHP > 4.3.2
      Is there anything change in "ereg_replace()" PHP > 4.3.2. Scripts works in PHP 4.3.1 but NOT in PHP 4.3.2: $text = "<!-- test -->"; $text =...
    3. #25399 [Opn->Bgs]: ereg_replace problem
      ID: 25399 Updated by: sniper@php.net Reported By: ibar at 163 dot com -Status: Open +Status: Bogus...
    4. #25399 [NEW]: ereg_replace problem
      From: ibar at 163 dot com Operating system: Redhat 7.2 PHP version: 4.3.3 PHP Bug Type: Scripting Engine problem Bug...
    5. better understanding of ereg_replace and other functions
      Hi everybody, Lot of places in manual i came across using "ereg_replace" or "ereg" is very resource intensive and hence its better to use...
  3. #2

    Default ereg_replace

    I'm using a piece of code i have used before with success only this time it
    doesn't seem to want to work, can anybody tell me where i've gone wrong with
    the following:
    -------CODE START-------
    $linked_comments=$comments_myrow["comment"];
    $linked_comments=stripslashes($linked_comments);
    $linked_comments = emoticon($linked_comments);
    $linked_comments = ereg_replace("\n","<br>",$linked_comments");
    $comments_author=$comments_myrow["author"];
    $comments_date=$comments_myrow["date_format(date, '%D %M %Y')"];
    $comments_time=$comments_myrow["date_format(date, '%H:%i')"];
    if ($SDK->is_supermod()) {
    $moderate = '<strong>- <a
    href="admin/comments_moderate.php?comment='.$ID.'&amp;storyID= '.$storyID.'">
    Moderate this post</a></strong>'; }
    ?>
    <tr>
    <td>
    <div align="justify" class='thin1'><?php echo("<strong><a
    href='".$SDK->board_url."/index.php?showuser=".$comments_author."'>".$SDK->i
    d2name($comments_author)."</a></strong><span class='edit'> -
    $comments_date - ".$comments_time."gmt
    ".$moderate."</span><br>$linked_comments"); ?></div>
    -------CODE END-------
    What I want to happen is every newline to be replaced with a <br> tag but in
    this instance it doesn't, the new lines are definately stored in the
    database. Can anyone help please?



    :::bc78::: Guest

  4. #3

    Default Re: ereg_replace

    All regular expressions need to be surrounded by slashes. For example:

    $linked_comments = ereg_replace("/\n/", "<br>", $linked_comments);

    But, as Hilarion pointed out, in your case, you don't need regexp

    On Fri, 6 Aug 2004 15:15:12 +0200, "Hilarion"
    <hilarion@SPAM.op.SMIECI.pl> wrote:
    >> $linked_comments = ereg_replace("\n","<br>",$linked_comments");
    >
    >Try:
    >
    >$linked_comments = str_replace("\r\n","\n",$linked_comments");
    >$linked_comments = str_replace("\n","<br>",$linked_comments");
    >
    >If you do not use regular expression for replacement, than
    >use str_replace instead of ereg_replace, wchich requires
    >esapeing spesial chars (I believe than newline char is special
    >char in regexp).
    >
    > Hilarion
    >
    eclipsboi Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139