简体   繁体   中英

php creating ics file - hidden characters and line breaks breaking output

I have a php page which should dynamically create an ics file for a calendar, with the content extracted from a database. For the most part this is fine but the description is causing problems.

When I examine the file in Notepad++ I can see xAO at regular intervals which I assume is down to the 75 octet limit - this is causing the two words to run together when viewed in Outlook.

How do I control this in php so it outputs to the next time rather than running the two words together? I've tried str_replace which a lot of variations to get a \\n string or \\\\n but to no avail.

Secondly, there are to CRLF between paragraphs. Again, I can't find a replace to handle this, and it's stopping the output at that point (ie cutting off any further details in the ics file) from being read in Outlook.

Here are some of code examples I've been going through from a lot of different sources in my research

//$description = wordwrap($description,39,"\n");
/*$description = str_replace(PHP_EOL,"--",$description);
$description = preg_replace('/\r\n|\r|\n/', "--", $description);
$description = str_replace("\r\n","---",$description);
$description = str_replace("\\n","---",$description);*/
$description = htmlentities($description, null, 'utf-8');
$description = str_replace(" ", "\\n", $description);
$description = trim($description);
//$description = htmlspecialchars_decode($description);

I managed to get the answers to both questions. For anyone else who finds this, the following worked for me:

$description = str_replace("\xA0", " ", $description);//nbsp - make space
$description = str_replace("\x0A", "", $description);//cr - remove

$desc_html = str_replace("\x0D","<br>",$description);//lf - html break

$description = str_replace("\x0D", "\\n", $description);//lf - text: escaped new line
$description = strip_tags(htmlspecialchars_decode($description));//clear html for plain text version

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM