Jump to content

[SOLVED] Word wrapping effectively to avoid ruining my layout


HoTDaWg

Recommended Posts

hey guys,

 

so in my textarea im using wrap="virtual" and it gets the job done.  The problem is that if a user were to type in a long string of A's or paste a link for example, this ruins my design when it shows up. 

 

Currently I am utilizing the word wrap function to place a <br> every 50 characters (which is how much, approximately width-wise, my textarea can hold per line); the problem is that assuming a user were to type his comment spread out on multiple lines, it would create a <br> for no reason just because its the 50th character, this is effecting my emoticon system.

 

here is a copy of the code:

<?php
$codes = array(''=>'<img src="includes/images/emoticon_tongue.png">',
	''=>'<img src="includes/images/emoticon_unhappy.png">',
	 ''=>'<img src="includes/images/emoticon_wink.png">',
	'XD'=>'<img src="includes/images/emoticon_evilgrin.png">',
	''=>'<img src="includes/images/emoticon_happy.png">',
	''=>'<img src="includes/images/emoticon_smile.png">',
	''=>'<img src="includes/images/emoticon_surprised.png">');
while($row = mysqli_fetch_array($result)){
	$newnewcomment = $row['comment_comment'];
	$dacomment = stripslashes($newnewcomment);
	$newnewnewcomment = wordwrap($dacomment,'50','<br>',true);
	$finalcomment = str_replace(array_keys($codes),array_values($codes),$newnewnewcomment);
	$comments .= '<hr><b>'.$row['comment_name'].'</b> Wrote on '
		. date('l, F jS, Y g:i A',$row['comment_date']).':<br><br>'
		. $finalcomment . '<br>';

}
?>

even if i placed the line that substitutes emoticons in front of the line that wraps the word, the wordwrap would include the <img src> tags and consider them as characters, it would place breaks within the image tags...

 

any ideas guys?:S

 

thanks,

 

HoTDawg

Link to comment
Share on other sites

nl2br does not work for me because assuming the user was to hold down the "a" key, a series of A's would appear and there would be no line breaks at all, this series of A's would need seperation as it could potentially ruin my layout. Thats why i have been using wordwrap, because it wraps long series of texts anyways, whether they have a /n or not

 

right now im thinking to create a custom function, that based on if the string has spaces it would put in a <br>

 

any other ideas?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.