For an iCal generator that I'm working on, I need to ensure that each 75 characters, a string is broken like this:
$string = "This is a long text. I use this text to demonstrate the PHP wordwrap function.";
$newstring = wordwrap($string, 75, "\r\n ", TRUE);
echo($newstring);
Result:
This is a long text. I use this text to demonstrate the PHP wordwrap
function.
iCal interprets the first space (from the wordwrap break parameter) as an indicator that the text property continues.
The wordwrap function removed the second space (from the string). After decoding the iCal content, the text would therefore look like this:
This is a long text. I use this text to demonstrate the PHP wordwrapfunction.
How can I work around this? I don't want the space from the string (between "wordwrap" and "function") to be removed.
3条答案
按热度按时间ibps3vxo1#
I have to use
chunk_split
instead. It will preserve the space and also not try to wrap at a space, which I don't need.Space preserved:
rtrim
is also used, aschunk_split
always appendsend
.This won't count the space within
end
, however. So if there are multiple lines, one could actually be 76 chars long. I changed thechunklen
parameter to 74, as this is good enough for my use case.q9rjltbz2#
Ok, While doing wordwrap pass an additional space so, that space between wordwrap and function will be retained.
Use this
Instead of
Output Before iCal:
Output After iCal:
w6mmgewl3#
It will always remove spaces, it's better to do your own function.
This will also ignore HTML tags.