I wonder if I could do this easier. It checks if $content has a YouTube link inside it. If it does, then it runs a jQuery $.getJson to get the thumbnail of it and so…
But I found it very sloppy made by me, but how else should this be coded:
$isY = preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=[0-9]/)[^&\n]+|(?<=v=)[^&\n]+#", $content, $matches);
if($isY) {
foreach(array_unique($matches) as $m) {
?>
<script>
$.getJSON (
'http://gdata.youtube.com/feeds/api/videos/<?php echo $m; ?>?v=2&alt=json-in-script&callback=?',
function(data) {
youtubeFetchDataCallback(data, <?php echo $show['id']; ?>);
}
);
</script>
<?php
}
}
Or is this okay?
I think the messiest part is the context switching. I would use string interpolation, and only open a single
<script>tag: