Here is what I am currently using for the code and it’s not working right.
I’ve tried making sense of literature and it’s not clicking
<?php
$con = mysql_connect("localhost","----","----");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("----", $con);
$result = mysql_query("SELECT * FROM posts");
while($row = mysql_fetch_array($result))
{
$str = 'post_content';
$str = preg_replace_callback('#(?:https?://\S+)|(?:www.\S+)|(?:\S+\.\S+)#', function($arr)
{
if(strpos($arr[0], 'http://') !== 0)
{
$arr[0] = 'http://' . $arr[0];
}
$url = parse_url($arr[0]);
// images
if(preg_match('#\.(png|jpg|gif)$#', $url['path']))
{
return '<img src="'. $arr[0] . '" />';
}
// youtube
if(in_array($url['host'], array('www.youtube.com', 'youtube.com'))
&& $url['path'] == '/watch'
&& isset($url['query']))
{
parse_str($url['query'], $query);
return sprintf('<iframe class="embedded-video" src="http://www.youtube.com/embed/%s" allowfullscreen></iframe>', $query['v']);
}
//links
return sprintf('<a href="%1$s">%1$s</a>', $arr[0]);
}, $str);
echo $str;
echo "<br />";
}
mysql_close($con);
?>
I know the problem is with $str = ‘post_content’; obviously it just shows a line for each line in mysql with just post_content.
What I want it to do is show all the values from the row post_content in MySQL and display the links as links , the youtube videos as youtube vids and the images and and so forth, but it’s not converting it.
Can anyone see what I am missing? If you could explain the tree of how it calls out that too I would love you greatly.
If you have a column
post_contentand want to fetch it, then instead of using the assignment$str = 'post_content';use: