Jump to content

[SOLVED] dont know what a couple things mean...


mike12255

Recommended Posts

So this line of code has everything in it i need to know.

 

#\[b\](.*?)\[/b\]#is'

 

First thing i don't know is why the # symbol is at the beginning what does it do?

Second thing i dont know is the (.*?) i take it it means and or something of that sorts?

and the last thing i dont understand is the #is what does that do?

 

Thanks for any help given :)

so does it give  (.*?) the value of $1?

 

im loooking off this example:

 

	$format_search =  array('#\[b\](.*?)\[/b\]#is', // Bold ([b]text[/b]
			'#\[i\](.*?)\[/i\]#is', // Italics ([i]text[/i]
			'#\[u\](.*?)\[/u\]#is', // Underline ([u]text[/u])
			'#\[s\](.*?)\[/s\]#is', // Strikethrough ([s]text[/s])
			'#\[quote\](.*?)\[/quote\]#is', // Quote ([quote]text[/quote])
			'#\[size=([1-9]|1[0-9]|20)\](.*?)\[/size\]#is', // Font size 1-20px [size=20]text[/size])
			'#\[color=\#?([A-F0-9]{3}|[A-F0-9]{6})\](.*?)\[/color\]#is', // Font color ([color=#00F]text[/color])
			'#\[url=(.*?)\](.*?)\[/url\]#i', // Hyperlink with descriptive text ([url=http://url]text[/url])
			'#\[url\](.*?)\[/url\]#i', // Hyperlink ([url]http://url[/url])
			'#\[img\](.*?)\[/img\]#i'); // Image ([img=http://url_to_image])
// The matching array of strings to replace matches with
$format_replace = array('<strong>$1</strong>',
			'<em>$1</em>',
			'<span style="text-decoration: underline;">$1</span>',
			'<span style="text-decoration: line-through;">$1</span>',
			'<blockquote>$1</blockquote>',
			'<pre>$1</'.'pre>',
			'<span style="font-size: $1px;">$2</span>',
			'<span style="color: #$1;">$2</span>',
			'<a href="$1">$2</a>',
			'<a href="$1">$1</a>',
			'<img src="$1" alt="" />');

Mostly right.  .*? is just some arbitrary pattern.  The important part is the parenthesis.  Any pattern can be inside the parenthesis.  You can even have captures nested inside of captures.  The variables $1, $2, $3, etc... populate in order of parenthesis appearance, from left to right. 

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.