Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Okay, so I figured out how to fix this issue. Thankfully, youtube is pretty consistent in the length of its links and the patterns of its URLs.</p> <p>1) Its hyperlink length, including "<a href="https://www.youtube.com/watch?w=" rel="nofollow">https://www.youtube.com/watch?w=</a>" tends to be around 43 to 44 characters long. However, this is not too unique. PHP.net's own hyperlinks, for example, can be this long and we do not want to use embed those links.</p> <p>2) The other factor, which makes the youtube hyperlinks unique for obvious reasons, is the afformentioned "<a href="https://www.youtube.com/watch?v=" rel="nofollow">https://www.youtube.com/watch?v=</a>" pattern.</p> <p>Using these two characteristics, we can create strlen and strpos statements that will look for anything simply posted as a youtube link in a message. The code will turn the video in the link of that message into an embeded video. If the poster puts anything else in the message, it will become a hyperlink instead. Here is the code;</p> <pre><code>$message = mysqli_real_escape_string($db_conn, $_POST['message']); $youtubecheck = strlen($message); if (($youtubecheck == '43') || ($youtubecheck == '44') &amp;&amp; strpos($message, "youtube.com/watch?v=")) { $message = '&lt;iframe width="535" height="400" src="' . str_replace('/watch?v=','/embed/',$message) . '"&gt;&lt;/iframe&gt;'; } else { function make_links_clickable($message) { return preg_replace('!(((f|ht)tp(s)?://)[-a-zA-Zа-яА-Я()0-9@:%_+.~#?&amp;;//=]+)!i', '&lt;a href="$1" target="_blank" STYLE="TEXT-DECORATION: NONE"&gt;&lt;b&gt;$1&lt;/b&gt;&lt;/a&gt;', $message); } $message = make_links_clickable($message); </code></pre> <p>Obviously, if the length of the hyperlink ever varies from the 43 and 44 character length, the first part of the if statement will not work and the link will become just a clickable link. But, this will be a very easy thing to fix. So far, this code addresses the issue.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload