PHP Code:
function BBCode ($string) {
$search = array(
'@\[(?i)b\](.*?)\[/(?i)b\]@si',
'@\[(?i)i\](.*?)\[/(?i)i\]@si',
'@\[(?i)u\](.*?)\[/(?i)u\]@si',
'%(@post#)(\d+)%',
'@\[(?i)img\](.*?)\[/(?i)img\]@si',
'@(?:https://)?(?:http://)?(?:www\.)?(?:youtube\.com/(?:v/|watch\?v=)|youtu\.be/)([\w-]+)(?:\S+)?@si',
'@\[(?i)url\](?:https?:\/\/)?(.*?)\[/(?i)url\]@si'
);
$replace = array(
'<b>\\1</b>',
'<i>\\1</i>',
'<u>\\1</u>',
'<a href="#$2" onclick="qp($2)">$1$2</a>',
'<img src="\\1" onclick="imagesize(this)" alt="~img broke/loading~" style="height:200px" />',
'<br><a href="https://youtu.be/$1" target="_blank">https://youtu.be/$1</a> <span onClick="ytvid("a$1")"><img id="a$1img" src="http://img.youtube.com/vi/$1/0.jpg" height="150px" style="display:block;"></span><embed id="a$1vid" width="600" height="425" src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" wmode="direct" allowfullscreen="true" style="display:none">',
'<a href="http://\\1" target="_blank">\\1</a>'
);
return preg_replace($search, $replace, $string);
}
function str_insert($str, $search, $insert) {
$index = strpos($str, $search);
if($index === false) {
return $str;
}
return substr_replace($str, $search.$insert, $index, strlen($search));
}
function generateRandomString($length = 5) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
$post1 = bbcode($post);
$randcode = generateRandomString();
$post1 = str_insert($post1, 'onClick="ytvid("a', $randcode);
$post1 = str_insert($post1, '<embed id="a', $randcode);
$post1 = str_insert($post1, '"><img id="a', $randcode);
$post1 = preg_replace('/(\r\n|\n|\r)/','<br>',$post1);
Hello, this is a chunk of code I have used on my custom forums for many months
It works extremely well, please ignore my youtube code part, as it's very good at what it does for my client side javascript for youtube videos & smartphones etc
I need help with getting URL's to auto embed, and youtube videos.. currently if a youtube video is posted, from youtu.be or youtube.com it'll auto embed it with my special stuff, it works amazingly.. however URL's have to be wrapped in the [url] I have thought of ghetto ways of fixing this in the past, however I want to be able to just post any youtube url & it slaps that into the code I have, or if you linked any link to a website (other than youtube) it'll just do a normal <a href= type deal
anyone able to help? skype or other places