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
If you wanna use strip_tags, then it would just be:
$content = strip_tags($data["Content"]);
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
Related
I have a string which contains html.
Example:
$content="<div>content<div style=''>some<div>another</div></div> <div>test</div> </div>";
I want to replace all divs without attributes, to paragraphs.
I tried
$content = preg_replace( '/<div>(.*?)<\/div>/', '<p>$1</p>', $content);
but it returns:
<p>content<div style=''>some<div>another</p></div> <p>test</p> </div>
which is not what I want. I want to replace all div without attributes to p.
What should I do?
Thank you!
$content = str_replace("<div>","<p>",$content);
$content = str_replace("</div>","</p>",$content);
echo $content
I am trying to PHP data that is posted from one place to another textarea.
Here is the case:
after doSearchTweet.php shows the tweets that are retrieved using twitter API, user can checked the tweets they want using a form.
The form will post the selected tweets a textarea input.
Here is the problem, I cannot style the selected tweets in the textarea.
For example: Username - Jakob Tweet - I need help in styling php!
I select this tweet and the data is post into the textarea, it shows this
JakobI need help in styling php!
instead of
Jakob
I need help in styling php!
I tried using normal html tags like <br/> n/ in the textarea, instead of applying the html tags, it will appear as normal text like this
Jakob< b r >I need help in styling php!
here is my code
<tr><td><label for="content"><span class="postBigFont">Content: </span></label></td>
<td colspan="4"><textarea cols="60" rows="15" name="content">
<?php
$user = $_POST['username'];
$content = $_POST['content'];
$add = $_POST['add'];
foreach ($add as $i){
echo $user[$i];
echo $content[$i];
}?>
</textarea></td></tr>
Replace "<br>" with "\n" in your textarea output.
Perhaps nl2br($text); is the answer
$content = str_replace("\r\n", "<br />", $content);
I have a textarea with input like this:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
I want an output with line breaks like this:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
How can I do that?
In my previous question, someone suggested wordwrap, which would be useful if the line had spaces.
Yes, use wordwrap...
$text = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
$newtext = wordwrap($text, 10, "<br />", true);
echo $newtext;
I don't know if I understand the question correctly, but HTML textarea field also has the wrap attribute (values "soft", "hard", or "off"). Hard wraps the words inside the text box and places line breaks at the end of each line so that when the form is submitted it appears exactly as it does in the text box.
So:
<textarea cols="30" rows="5" wrap="hard">text..</textarea>
you could insert a "<br /> at the index, where the break should occur - only for the output.
textbox.value = HandleLineBreaks(line, index);
Hi so i was wondering how do i get a load of string from a mysql database and put them in a input area with a return between each value such as
Hi
My
Name
Is
Joris
Thanks,
Joris
When you're creating a <textarea> in a form, the text between the <textarea> and </textarea> tags is the default text for the text area. You just need to build a pair of these with the string you want between them, like this: <textarea>$string</textarea>. Do the query and the concatenating in PHP using \n for newlines.
You can simply add a carriage return after each string and then output this within the required textarea.
For example:
<?php
$cr = "\n";
$bigString = 'Hello' . $cr . 'there.';
echo '<textarea>' . $bigString . '</textarea>';
?>
i have a textarea with ckeditor customized toolbar which user can only select smiley
now i want users can only use smilys and new line function
so if $comment is my raw text output with html tags and i want only smiley and text with new lines appeared in output not other html tags
sample raw data :
<p>
this is a sample text</p>
<p>
<img alt="angry" src="includes/ckeditor/plugins/smiley/images/angry_smile.gif" title="angry" /></p>
<p>
text for sample</p>
for new line in html :
$comment = nl2br($comment);
but what about showing only smileys ?!
As I answered in your previous question, encode your output with htmlspecialchars and then use nl2br to convert new lines to <br> tags.
To replace text smilies with graphics, you want a series of regular expressions rather than attempting to explode the string and output it in pieces.
The following should give you some idea:
$comment = htmlspecialchars(comment);
$comment = nl2br($comment);
$smilies = array(
'/\b:\)\b/' => '<img src="smile.gif" />', // :)
'/\b:\(\b/' => '<img src="sad.gif" />', // :(
'/\b:p\b/' => '<img src="tongue.gif" />', // :p
);
$comment = preg_replace(array_keys($smilies), $smilies, $comment);
If I understood you correctly, then here is reference, to what you might need: strip_tags
Here is what I came up with:
function smileAndText( $some_text = '' ) {
if( ! empty( $some_text ) ) {
$some_text = nl2br( $some_text );
$some_text = strip_tags( $some_text, '<img><br />' );
}
return $some_text;
}
Look at php strip_tags http://php.net/manual/en/function.strip-tags.php. You could do something like
$comment = strip_tags(nl2br($comment),"<br />, #smiley_tag");
Not sure exactly what you're trying to do with the smileys, but there is a way to configure CK in the javascript config file to use when the enter key is pressed. I'd still think about post-process replacing, but that's a good way to make clean code happen on the front end.