Jump to content

preg_replace "Deleminator must not be alphanumeric or \"


d22552000

Recommended Posts

Well here is my php code, yes it has tabs so it will mess up here but the code is fine, the bottom regexp replacements for the url both work, its the top eight that return errors.

 

Submitting Message...

[center] Testing [/center]

Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash
Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash
Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash
Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash
Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash
Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash
Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash

 

Please tell me what is wrong.

 

	echo "Submitting Message...<br />" . $_POST['message'];
$_POST['message'] = htmlspecialchars($_POST['message']);

############################################################

$_POST['message'] = preg_replace("\[b\](.+?)\[\/b\]",
	" <strong>$1</strong>", $_POST['message']);

$_POST['message'] = preg_replace("\[i\](.+?)\[\/i\]",
	" <em>$1</em>", $_POST['message']);

$_POST['message'] = preg_replace("\[u\](.+?)\[\/u\]",
	" <u>$1</u>", $_POST['message']);

############################################################

$_POST['message'] = preg_replace("\[img\](.+?)\[\/img\]",
	" <img alt=\"$1\" src=\"$1\" />", $_POST['message']);

############################################################

$_POST['message'] = preg_replace("\[left\](.+?)\[\/left\]",
	" <div align=\"left\">$1</div>", $_POST['message']);

$_POST['message'] = preg_replace("\[center\](.+?)\[\/center\]",
	" <div align=\"center\">$1</div>", $_POST['message']);

$_POST['message'] = preg_replace("\[right\](.+?)\[\/right\]",
	" <div align=\"right\">$1</div>", $_POST['message']);

############################################################

$_POST['message'] = preg_replace("/([a-zA-Z]+:\/\/[a-z0-9\_\.\-]+".
	"[a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%\=\,\.]+)/",
	" <a href=\"$1\" target=\"_blank\">$1</a>", $_POST['message']);

$_POST['message'] = preg_replace("/[^a-z]+[^:\/\/](www\.".
	"[^\.]+[\w][\.|\/][a-zA-Z0-9\/\*\-\?\&\%\=\,\.]+)/",
	" <a href=\"http://$1\" target=\"_blank\">$1</a>", $_POST['message']);

############################################################

$_POST['message'] = trim(addslashes($_POST['message']));

this is a pattern error, enclose all of your patterns with "/ -pattern- /" and make sure to escape any / (forward slashes) in your pattern.

 

 

eg:

	$_POST['message'] = preg_replace("/\[b\](.+?)\[\/b\]/",
	" <strong>$1</strong>", $_POST['message']);

$_POST['message'] = preg_replace("/\[i\](.+?)\[\/i\]/",
	" <em>$1</em>", $_POST['message']);

$_POST['message'] = preg_replace("/\[u\](.+?)\[\/u\]/",
	" <u>$1</u>", $_POST['message']);

 

hope this helps,

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.