I am building an application using cakephp v4.
Should save JSON object including HTML content type while creating an event in MS graph api.
$description = '<span class="is-size-6" style="font-style: normal; font-weight: 400;">Microsoft Teams Meeting</span><span style="font-style: normal; font-weight: 400;"></span><div class="is-flex is-flex-direction-column mt-3"><span style="font-weight: 700;">The meeting url will be added here.</span><a href="https://aka.ms/JoinTeamsMeeting" target="_blank">Learn More</a></div>';
$event = '{
"subject": "Hello World",
"body": {
"contentType": "HTML",
"content": "' . h($description) . '",
},
...
}';
If I fetch the saved event, then the body->content looks like:
<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta content=\"text/html; charset=us-ascii\">\r\n</head>\r\n<body>\r\n<span class="is-size-6" style="font-style: normal; font-weight: 400;">Microsoft Teams Meeting</span><span style="font-style: normal; font-weight: 400;"></span><div class="is-flex is-flex-direction-column mt-3"><span style="font-weight: 700;">The meeting url\r\n will be added here.</span><a href="https://aka.ms/JoinTeamsMeeting" target="_blank">Learn More</a></div>\r\n</body>\r\n</html>\r\n"
I want to show the HTML content in textarea element.
What I tried is to use php htmlentities function.
But it still has HTML tags like the following image.
How to show only strings like the first image?
My Answer:
To convert HTML content to a string in CakePHP, you can use the `strip_tags` function in PHP. Here's how you can modify your code to achieve this:
php
$description = 'Microsoft Teams MeetingThe meeting url will be added here.Learn More';
$event = '{
"subject": "Hello World",
"body": {
"contentType": "HTML",
"content": "' . strip_tags($description) . '",
},
...
}';
By using `strip_tags` function, you can remove all HTML tags from the `$description` variable and only keep the text content. This will allow you to display the content as a string without any HTML tags in a textarea element.
Rate this post
4 of 5 based on 5082 votesComments