Archive for January, 2011

PHP Get Content Between Characters

Recently, I needed to get the content of an email address formatted as “Tim Barsness ” as just the email address “email@address.com”. I wrote a function to do so. It ended up being pretty straight forward.

function getContentBetween($content, $lead, $trail)
{
	//Gets content after last occurrence of $lead as $between_split[count($from_split)]
	$between_split = split($lead, $content);
	//Gets content before $trail as $between_split[0]
	$between_split = split($trail, $between_split[count($from_split)]);
	return $between_split[0];
}

Which can be used as follows:

$email = 'Tim Barsness <email@address.com>';
 
echo getContentBetween($email, '<', '>');  //returns email@address.com

How do I Escape Javascript in XHTML for Validation

I’ve been doing some W3C validation lately and needed to look up how to escape javascript in documents with an XHTML transitional DTD. Here goes:

<script language="javascript" type="text/javascript">
/* <![CDATA[ */
$(document).ready(function(){
	//jQuery (or other javascript) fun goes here!!
});
/* ]]> */
</script>