Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed help understanding create_function() and regex
    primarykey
    data
    text
    <p>After allot of searching around SO and other forums also stumbling over various php function documentation, I tried to edit a function that I found on here(converts URLs to clickable links) so it will also handle embedded video, unfortunately my skill set is poor and I believe I don't fully understand <code>create_function()</code> to be successful at this.</p> <p>So here's my scrambled egg code:</p> <pre><code>private function _check4Links($text){ $pattern = '#\b(([\w-]+://?|www[.])[^\s()&lt;&gt;]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#'; $callback = create_function('$matches', ' $url = array_shift($matches); $url_parts = parse_url($url); if(preg_match("%(?:youtube\.com/(?:user/.+/|(?:v|e(?:mbed)?)/|.*[?&amp;]v=)|youtu\.be/)([^"&amp;?/ ]{11})%i", $url, $match)){ return sprintf(\'&lt;iframe title="YouTube video player" class="youtube-player" type="text/html" width="400" height="244" src="http://www.youtube.com/embed/\'.$match[1].\'" frameborder="0" allowFullScreen&gt;&lt;/iframe&gt;\', $url, $text); }else{ $text = parse_url($url, PHP_URL_HOST) . parse_url($url, PHP_URL_PATH); $text = preg_replace("/^www./", "", $text); $last = -(strlen(strrchr($text, "/"))) + 1; if ($last &lt; 0) { $text = substr($text, 0, $last) . "&amp;hellip;"; } return sprintf(\'&lt;a target="_blank"rel="nofollow" href="%s"&gt;%s&lt;/a&gt;\', $url, $text); }'); return preg_replace_callback($pattern, $callback, $text); } </code></pre> <p>I should also mention that i'm <strong>not</strong> looking for someone to just show me the correct code, I'm looking for someone to explain to me why my code is not working and what i am doing wrong. Thank you for your time :)</p>
    singulars
    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.
    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