How can PHP be used to make URLs and email addresses clickable within the description of events from a Google Calendar feed?
To make URLs and email addresses clickable within the description of events from a Google Calendar feed, you can use PHP to parse the description text and convert them into clickable links. This can be achieved by using regular expressions to identify URLs and email addresses within the text, and then wrapping them in anchor tags with the appropriate href attribute.
<?php
function makeClickable($text) {
$text = preg_replace('/(https?:\/\/[^\s]+)/', '<a href="$1" target="_blank">$1</a>', $text);
$text = preg_replace('/([^\s]+@[^\s]+)/', '<a href="mailto:$1">$1</a>', $text);
return $text;
}
// Sample event description from Google Calendar feed
$eventDescription = "Join us at http://example.com for more information. Contact us at info@example.com for inquiries.";
echo makeClickable($eventDescription);
?>