Return to Snippet

Revision: 53026
at November 10, 2011 09:43 by Waldio


Initial Code
<?php

$unparsedText = <<<'EOT'
	@cowb: Je moet dit en dit gebruiken....
EOT;

function replies( $matches )
{
	$username = $matches[1]; // [1] is de eerste match, [2] de tweede, enz.

	$sQuery = "
		SELECT
			id
		FROM
			users
		WHERE
			username = '".mysql_real_escape_string($username)."'
	";

	$result = mysql_query($sQuery, $connection);

	if( !$result && mysql_num_rows($result) > 0 )
	{
		$row = mysql_fetch_assoc($result) )

		return '@<a href="'.$result['id'].'">'.$username.'</a>';
	}
}

$parsedText = preg_replace_callback('/@(.*?):/si', 'replies', $unparsedText);

Initial URL


Initial Description


Initial Title
Preg_replace_callback with UBB-parser

Initial Tags


Initial Language
PHP