[PHP] wordwrap function (that skips html tags)
hello! i found a nice function that i would like to use but unfortunately there is a problem i can not solve. for my notepool device it would be great to use php's wordwrap function but because the string that needs to be wordwrapped contains also html tags i can not use this function like this. on php.net (manual: wordwrap) i found a user contribution with a wordwrap function that skips html tags (and forces words to split at a desired width). the bad thing about it is that in the output some characters are missing. example: as i enter this url into my form: http://www2.snm-hgkz.ch/~rieger/notepool/addnote.php that's the output: h tp://www2.snm-hgkz ch/~rieger/notepool/ ddnote.php (obviously some caracters are missing, the first 't' of http or the 'a' of addnote.php for instance.) can you tell me what needs to be modified to get rid of this side effect (or do you have another idea how to use wordwrap in a way it skips html tags and forces words to split)? this is the function: function sheep_wordwrap($str,$cols,$non_prop,$cut,$exclude1,$exclude2){ $count=0; $tagcount=0; $str_len=strlen($str); //$cut= $cut ; $calcwidth=0; for ($i=1; $i=$str_len;$i++){ $str_len=strlen($str); if ($str[$i]==$exclude1) $tagcount++; elseif ($str[$i]==$exclude2){ if ($tagcount0) $tagcount--; } else{ if (($tagcount==0)){ if (($str[$i]==' ') || ($str[$i]==\n)) $calcwidth=0; else{ if ($non_prop){ if (ereg(([QWOSDGCM#@m%w]+),$str[$i],$matches)) $calcwidth=$calcwidth+7; elseif (ereg(([I?\|()\]+),$str[$i],$matches)) $calcwidth=$calcwidth+4; elseif (ereg(([i']+),$str[$i],$matches)) $calcwidth=$calcwidth+2; elseif (ereg(([!]+),$str[$i],$matches)) $calcwidth=$calcwidth+3; else{ $calcwidth=$calcwidth+5; } } else{ $calcwidth++; } if ($calcwidth$cols){ $str=substr($str,0,$i-1).$cut.substr($str,$i,$str_len-1); $calcwidth=0; } } } } } return $str; //moby rules at 5am! :) } and here i call it: $str = $message; $cols = 100; $cut = \n; $non_prop = true; $exclude1 = ; $exclude2 = ; $str = sheep_wordwrap($str,$cols,$non_prop,$cut,$exclude1,$exclude2); echo $str; thanks a lot for your help! philipp * http://www2.snm-hgkz.ch/~rieger/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] wordwrap function (that skips html tags)
Hello, What's your php version? Take at look at: http://www.php.net/manual/en/function.wordwrap.php and http://www.php.net/manual/en/function.strip-tags.php b.e. $str='http://www2.snm-hgkz.ch/~rieger/notepool/addnote.php'; echo wordwrap(strip_tags($str),8,'br',1); i you can't use wordwrap(), try: ? /* written by [EMAIL PROTECTED] */ function wordwraphtml($string,$length,$endline='br',$striphtml=true) { if($striphtml)$string=strip_tags($string); $temp=''; $sublength=strlen($string); if($sublength$length)return $string; while($sublength$length) { $temp.=substr($string,0,$length).$endline; $string=substr($string,$length+1); $sublength=strlen($string); } return $temp; } $string='a href=http://www.startpunt.cc/a'; echo wordwraphtml($string,8); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] wordwrap doesn't work for customer's Outlook
Is there really no solution to this issue? Is everyone using wordwrap to wrap their newsletter texts, or is there a way that works as well with Ms Outlook? Thanks a lot Recap: - Ms Outlook gets everything on 1 line when I use wordwrap( $text,76,\r\n ). - Ms Outlook shows nice line breaks when they are hard-coded in the script. At 23:33 24.06.02, you wrote: So can anyone tell me what is the difference between wordwrap and these hard-coded lines? Is wordwrap not safe for use in newsletter sending scripts? Why is $newtext = wordwrap( $text,76,\r\n ); not sufficient? Thanks a lot -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] wordwrap doesn't work for customer's Outlook
Hello What would *you* do if you wordwrap a text and send it via the mail() command, and your costumer gets the whole text on 1 single line? I'm using $newtext = wordwrap( $text,76,\r\n ); He has Outlook. When I'm testing it in my Eudora, in Bat and in Outlook Express, it's wrapped nicely. (So far the headers end with \n and not with \r\n - may this have an influence on the resulting email body? I cannot run 33 tests, because the only one who can test it for me is the customer...) TIA Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] wordwrap doesn't work for customer's Outlook
This is really frustrating: We found two versions of Outlook on different machines, that have been installed with the default settings, that 'eat' the line breaks which were made with PHP's wordwrap() function. There are no line breaks at all! On one of the machines there's also a version of Outlook Express, and this one shows the line breaks. Also in Eudora and in Bat, the line breaks are ok. Important detail, the footer of the newsletter is hardcoded in the PHP script with physical line breaks like \n . \n . Copyright?\n . --\n . These work! So can anyone tell me what is the difference between wordwrap and these hard-coded lines? Is wordwrap not safe for use in newsletter sending scripts? Why is $newtext = wordwrap( $text,76,\r\n ); not sufficient? Thanks a lot -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] wordwrap not working
Hi, Im testing the example in the http://www.php.net/manual/en/function.wordwrap.php and it seems not working it still printing the whole word and not wrapping. Im using php4.05 in my redhat 6.2 using an apache. Here's the sample: ? $text = The quick brown fox jumped over the lazy dog.; $newtext = wordwrap( $text, 20 ); echo $newtext\n; ? it should print like this: The quick brown fox jumped over the lazy dog. but it still printing like this: The quick brown fox jumped over the lazy dog. Please help Regards, Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] wordwrap not working
Are you looking at the output in a web browser? Martin -Original Message- From: Michael P. Carel [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 21, 2002 2:25 PM To: php Subject: [PHP] wordwrap not working Hi, Im testing the example in the http://www.php.net/manual/en/function.wordwrap.php and it seems not working it still printing the whole word and not wrapping. Im using php4.05 in my redhat 6.2 using an apache. Here's the sample: ? $text = The quick brown fox jumped over the lazy dog.; $newtext = wordwrap( $text, 20 ); echo $newtext\n; ? it should print like this: The quick brown fox jumped over the lazy dog. but it still printing like this: The quick brown fox jumped over the lazy dog. Please help Regards, Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] wordwrap not working
If your viewing the output through a browser, try this; ? $text = The quick brown fox jumped over the lazy dog.; $newtext = wordwrap( $text, 20, br); echo $newtext\n; ? -Original Message- From: Michael P. Carel [mailto:[EMAIL PROTECTED]] Sent: Thursday, 21 February 2002 1:25 PM To: php Subject: [PHP] wordwrap not working Hi, Im testing the example in the http://www.php.net/manual/en/function.wordwrap.php and it seems not working it still printing the whole word and not wrapping. Im using php4.05 in my redhat 6.2 using an apache. Here's the sample: ? $text = The quick brown fox jumped over the lazy dog.; $newtext = wordwrap( $text, 20 ); echo $newtext\n; ? it should print like this: The quick brown fox jumped over the lazy dog. but it still printing like this: The quick brown fox jumped over the lazy dog. Please help Regards, Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] wordwrap not working
snip it should print like this: The quick brown fox jumped over the lazy dog. but it still printing like this: The quick brown fox jumped over the lazy dog. HTML treats bunches of whitespace as one space. Look at the source of the page; you'll see that it's doing what it should. If you want your HTML to appear wordwrapped, modify your PHP to use the 'nl2br()' function: ? $text = The quick brown fox jumped over the lazy dog.; $newtext = nl2br(wordwrap( $text, 20 )); echo $newtext\n; ? This will convert all newlines to br tags, and your HTML output will look just like your text output. Joel -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] wordwrap not working
If your viewing the output through a browser, try this; ? $text = The quick brown fox jumped over the lazy dog.; $newtext = wordwrap( $text, 20, br); echo $newtext\n; ? Ah, this is a better solution than mine -- I didn't know wordwrap had the 3rd (and 4th) parameters till now. Joel -- [ joel boonstra | [EMAIL PROTECTED] ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] wordwrap not working
This may be a nl2br() problem. If you are setting \n as your newline character, it probably needs to be br if your just echoing it. Depending on where it ultimately gets displayed, you'll want one or the other. For example, sending an email message you want \n. Steven J. Walker Walker Effects www.walkereffects.com [EMAIL PROTECTED] On Wednesday, February 20, 2002, at 07:25 PM, Michael P. Carel wrote: Hi, Im testing the example in the http://www.php.net/manual/en/function.wordwrap.php and it seems not working it still printing the whole word and not wrapping. Im using php4.05 in my redhat 6.2 using an apache. Here's the sample: ? $text = The quick brown fox jumped over the lazy dog.; $newtext = wordwrap( $text, 20 ); echo $newtext\n; ? it should print like this: The quick brown fox jumped over the lazy dog. but it still printing like this: The quick brown fox jumped over the lazy dog. Please help Regards, Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] wordwrap
Hey Hey! I've got a question about wordwrap. It seems that when I run this on a string that contains spaces, if my replacement string happens to fall on a space, the space is removed completely from the string. This isn't good :-\ Any way around this? Thanks! - Scott -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] wordwrap()
Maybe I'm not using it right, but I'm using the sample in the manual. Here's the code: ? $text = A very long wrd.; $newtext = wordwrap( $text, 8, \n, 1); echo $newtext\n; ? Here's the output: A very long wooo ord. Here's what the manual says the output should be: A very long wooo ord. Has anyone else had troubles with the wordwrap() function? Do I need to compile php with another flag to get this to work properly? Thanks, Tyler -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] wordwrap()
i know this is a silly question, but you're not looking at it thru a web browser, are you? browsers are for HTML and markup code. the output on my computer is the same as the manual output: A very long wooo ord. -Original Message- From: Tyler Longren [mailto:[EMAIL PROTECTED]] Subject: [PHP] wordwrap() Maybe I'm not using it right, but I'm using the sample in the manual. Here's the code: ? $text = A very long wrd.; $newtext = wordwrap( $text, 8, \n, 1); echo $newtext\n; ? Here's the output: A very long wooo ord. Here's what the manual says the output should be: A very long wooo ord. Has anyone else had troubles with the wordwrap() function? Do I need to compile php with another flag to get this to work properly? Thanks, Tyler -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] wordwrap()
Well, that was easy. I never even thought to change the \n to br. Thanks for helping me over my mental block... Tyler - Original Message - From: scott [gts] [EMAIL PROTECTED] To: php [EMAIL PROTECTED] Sent: Tuesday, July 17, 2001 10:25 AM Subject: RE: [PHP] wordwrap() i know this is a silly question, but you're not looking at it thru a web browser, are you? browsers are for HTML and markup code. the output on my computer is the same as the manual output: A very long wooo ord. -Original Message- From: Tyler Longren [mailto:[EMAIL PROTECTED]] Subject: [PHP] wordwrap() Maybe I'm not using it right, but I'm using the sample in the manual. Here's the code: ? $text = A very long wrd.; $newtext = wordwrap( $text, 8, \n, 1); echo $newtext\n; ? Here's the output: A very long wooo ord. Here's what the manual says the output should be: A very long wooo ord. Has anyone else had troubles with the wordwrap() function? Do I need to compile php with another flag to get this to work properly? Thanks, Tyler -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] wordwrap
There no tag, but a function wordwrap(). http://www.php.net/manual/en/function.wordwrap.php You need to separate vars into message and comments also. Programming in any language w/o reading manual/reference is just a waste of time. IMO. Regards, -- Yasuo Ohgaki shawn [EMAIL PROTECTED] wrote in message 001401bfb6eb$78186e20$[EMAIL PROTECTED]">news:001401bfb6eb$78186e20$[EMAIL PROTECTED]... Is there a tag in php that acts like wordwrap=virtual does in html? I have a script that is sending out variables in a email from a contact form, but for a comments section it will not wordwrap in the email. Thanks Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] wordwrap
Is there a tag in php that acts like wordwrap=virtual does in html? I have a script that is sending out variables in a email from a contact form, but for a comments section it will not wordwrap in the email. Thanks Shawn
RE: [PHP] wordwrap
Is there a tag in php that acts like wordwrap=virtual does in html? I have a script that is sending out variables in a email from a contact form, but for a comments section it will not wordwrap in the email. Thanks Shawn You need to use line breaks \n for lines to wrap in email. Jeff Oien http://www.webdesigns1.com/php/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] wordwrap() in php4.03pl1 does not work(?)
It's working for me. How is your call coded? "Nicole Lallande" [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Sheesh - I forgot - the function is wordwrap() Nicole Lallande wrote: Hi All, Am trying to use this function which in the manual is defined as working in versions of php 4.02 -- well, I qualify - but the feature does not work. Anyone know what is going on? TIA, Nicole -- Nicole Lallande [EMAIL PROTECTED] 760.753.6766 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- Nicole Lallande [EMAIL PROTECTED] 760.753.6766 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] wordwrap() in php4.03pl1 does not work(?)
Hi All, Am trying to use this function which in the manual is defined as working in versions of php 4.02 -- well, I qualify - but the feature does not work. Anyone know what is going on? TIA, Nicole -- Nicole Lallande [EMAIL PROTECTED] 760.753.6766 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] wordwrap() in php4.03pl1 does not work(?)
Sheesh - I forgot - the function is wordwrap() Nicole Lallande wrote: Hi All, Am trying to use this function which in the manual is defined as working in versions of php 4.02 -- well, I qualify - but the feature does not work. Anyone know what is going on? TIA, Nicole -- Nicole Lallande [EMAIL PROTECTED] 760.753.6766 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- Nicole Lallande [EMAIL PROTECTED] 760.753.6766 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]