|    
			
				05/10/2012, 13:04
			
			
			  | 
  |   |  |  |  Fecha de Ingreso: agosto-2012 Ubicación: M. 
						Mensajes: 2.031
					 Antigüedad: 13 años, 2 meses Puntos: 52 |  | 
  |  Respuesta: Saber si url de youtube  son validos con php.  
   Cita:  
					Iniciado por Triby   Wordpress usa esto: 
Código PHP:
 Ver original1454 /**1455     * Callback to convert URI match to HTML A element.1456     *1457     * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link1458     * make_clickable()}.1459     *1460     * @since 2.3.21461     * @access private1462     *1463     * @param array $matches Single Regex Match.1464     * @return string HTML A element with URI address.1465     */1466    function _make_url_clickable_cb($matches) {1467            $url = $matches[2];1468    1469            if ( ')' == $matches[3] && strpos( $url, '(' ) ) {1470                    // If the trailing character is a closing parethesis, and the URL has an opening parenthesis in it, add the closing parenthesis to the URL.1471                    // Then we can let the parenthesis balancer do its thing below.1472                    $url .= $matches[3];1473                    $suffix = '';1474            } else {1475                    $suffix = $matches[3];1476            }1477    1478            // Include parentheses in the URL only if paired1480                    $suffix = strrchr( $url, ')' ) . $suffix;1482            }1483    1484            $url = esc_url($url);1486                    return $matches[0];1487    1488            return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>" . $suffix;1489    }1490    1491    /**1492     * Callback to convert URL match to HTML A element.1493     *1494     * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link1495     * make_clickable()}.1496     *1497     * @since 2.3.21498     * @access private1499     *1500     * @param array $matches Single Regex Match.1501     * @return string HTML A element with URL address.1502     */1503    function _make_web_ftp_clickable_cb($matches) {1504            $ret = '';1505            $dest = $matches[2];1506            $dest = 'http://' . $dest;1507            $dest = esc_url($dest);1509                    return $matches[0];1510    1511            // removed trailing [.,;:)] from URL1513                    $ret = substr($dest, -1);1515            }1516            return $matches[1] . "<a href=\"$dest\" rel=\"nofollow\">$dest</a>$ret";1517    }1518    1519    /**1520     * Callback to convert email address match to HTML A element.1521     *1522     * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link1523     * make_clickable()}.1524     *1525     * @since 2.3.21526     * @access private1527     *1528     * @param array $matches Single Regex Match.1529     * @return string HTML A element with email address.1530     */1531    function _make_email_clickable_cb($matches) {1532            $email = $matches[2] . '@' . $matches[3];1533            return $matches[1] . "<a href=\"mailto:$email\">$email</a>";1534    }1535    1536    /**1537     * Convert plaintext URI to HTML links.1538     *1539     * Converts URI, www and ftp, and email addresses. Finishes by fixing links1540     * within links.1541     *1542     * @since 0.711543     *1544     * @param string $text Content to convert URIs.1545     * @return string Content with converted URIs.1546     */1547    function make_clickable( $text ) {1548            $r = '';1549            $textarr = preg_split( '/(<[^<>]+>)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // split out HTML tags1550            foreach ( $textarr as $piece ) {1551                    if ( empty( $piece ) || ( $piece[0] == '<' && ! preg_match('|^<\s*[\w]{1,20}+://|', $piece) ) ) {1552                            $r .= $piece;1553                            continue;1554                    }1555    1556                    // Long strings might contain expensive edge cases ...1557                    if ( 10000 < strlen( $piece ) ) {1558                            // ... break it up1559                            foreach ( _split_str_by_whitespace( $piece, 2100 ) as $chunk ) { // 2100: Extra room for scheme and leading and trailing paretheses1560                                    if ( 2101 < strlen( $chunk ) ) {1561                                            $r .= $chunk; // Too big, no whitespace: bail.1562                                    } else {1563                                            $r .= make_clickable( $chunk );1564                                    }1565                            }1566                    } else {1567                            $ret = " $piece "; // Pad with whitespace to simplify the regexes1568    1569                            $url_clickable = '~1570                                    ([\\s(<.,;:!?])                                        # 1: Leading whitespace, or punctuation1571                                    (                                                      # 2: URL1572                                            [\\w]{1,20}+://                                # Scheme and hier-part prefix1573                                            (?=\S{1,2000}\s)                               # Limit to URLs less than about 2000 characters long1574                                            [\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]*+         # Non-punctuation URL character1575                                            (?:                                            # Unroll the Loop: Only allow puctuation URL character if followed by a non-punctuation URL character1576                                                    [\'.,;:!?)]                            # Punctuation URL character1577                                                    [\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]++ # Non-punctuation URL character1578                                            )*1579                                    )1580                                    (\)?)                                                  # 3: Trailing closing parenthesis (for parethesis balancing post processing)1581                            ~xS'; // The regex is a non-anchored pattern and does not have a single fixed starting character.1582                                  // Tell PCRE to spend more time optimizing since, when used on a page load, it will probably be used several times.1583    1585    1586                            $ret = preg_replace_callback( '#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is', '_make_web_ftp_clickable_cb', $ret );1587                            $ret = preg_replace_callback( '#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret );1588    1589                            $ret = substr( $ret, 1, -1 ); // Remove our whitespace padding.1590                            $r .= $ret;1591                    }1592            }1593    1594            // Cleanup of accidental links within links1595            $r = preg_replace( '#(<a( [^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i', "$1$3</a>", $r );1596            return $r;1597    }
Elimina los números de línea y adáptalo para agregar la opción de los videos. Disculpa en el parametro Matches debo poner la cadena de texto que puede contener urls verdad?      |