2

i have a textarea value which its value derived from a field(nl2br)

how to strip off "< br/>", so that when i want to edit this field, the "< br />" will not be appeared?

//$data["Content"] is the field that has <br/> tags inside
$content = $data["Content"];

//when want to edit, want to strip the <br/> tag
<td><textarea name="content" rows="10" style="width:300px;"><?=$content?></textarea></td>

i know it should be using strip_tags() function but not sure the real way to do it

any help would be appreciated

user723360
  • 77
  • 2
  • 7
  • 1
    i have found the way finally. just use strip_tags($content) and it should work fine. – user723360 May 29 '11 at 12:11
  • use `strip_tags()` if you wanna remove every html element from your variable, if you wanna just remove the `
    ` use a function like `str_replace()`. if you are editing for example blog posts you better add a javascript editor in your interface, it'll make your like much easier
    – afarazit May 29 '11 at 12:15

2 Answers2

4

If you wanna use strip_tags, then it would just be:

$content = strip_tags($data["Content"]);
Niklas
  • 29,752
  • 5
  • 50
  • 71
2

i would be using str_replace the following will replace <br/> with newline

$content = str_replace('<br/>','\n',$data['Content']);

or if you don't want the newline

$content = str_replace('<br/>','',$data['Content']);

edit an example

$my_br = 'hello<br/> world';
$content = str_replace('<br/>','',$my_br);

echo $content;

Output: hello world
afarazit
  • 4,907
  • 2
  • 27
  • 51
  • 1
    That won't remove
    or
    – Niklas May 29 '11 at 12:16
  • @Niklas but it'll remove `
    ` and not the rest of the html element. he only requested `
    – afarazit May 29 '11 at 12:18
  • yea this won't replace the
    in fact.. so i think i will stick with the strip_tags()
    – user723360 May 29 '11 at 12:19
  • @user723360 of course it does, check my example, keep in mind that this only removes `
    ` not `
    ` or `
    `. If you like to remove all and only the occurrences of `
    ` you must run `str_replace` for all of the above.
    – afarazit May 29 '11 at 12:22
  • @atno i not sure why.. perhaps the nl2br problem as the value get from database. i have try this $content = str_replace('
    ','\n',$data['Content']); but the
    tags still appear in the textarea.
    – user723360 May 29 '11 at 12:25
  • @user723360 `$content = str_replace('
    ','',$data['Content']);` you must assign the output of str_replace to a variable and then print it on the screen
    – afarazit May 29 '11 at 12:28