Sticky Posts
Feb 3, 2009
Easier Copy-Pasteable Code | And 2 Sample Functions
I just wrote a plugin using jQuery to convert CODE blocks to TEXTAREA alternatives. It works ... not MSIE but fk it, I'm not that good yet (to make shit work in IE) ... and it will be easier for you to copy-paste in non-Opera browsers. You will notice two links above each CODE block and clicking each will switch between hightlighted view and raw-text view. Hope it helps you to snatch my code easier.
And some sample code for you!
These are two string functions I use a lot and could be cool for you. String startswith and endswith in PHP.
<?php
// ------------------------------------------------------------
if(!function_exists('el_strings_startsWith')){
function el_strings_startsWith($str, $part, $case = true){
$strlen = strlen($str); $partlen = strlen($part);
if($strlen < $partlen) return false;
return (bool)!($case ? strncmp($str,$part,$partlen) : strncasecmp($str,$part,$partlen));
}
function el_strings_startsWithI($str, $part){
return el_strings_startsWith($str, $part, false);
}
}
// ------------------------------------------------------------
if(!function_exists('el_strings_endsWith')){
function el_strings_endsWith($str, $part, $case = true){
$strlen = strlen($str); $partlen = strlen($part);
if($strlen < $partlen) return false;
$str = substr($str,$strlen-$partlen);
return (bool)!($case ? strncmp($str,$part,$partlen) : strncasecmp($str,$part,$partlen));
}
function el_strings_endsWithI($str, $part){
return el_strings_endsWith($str, $part, false);
}
}
// ------------------------------------------------------------
?>
Tell me if it works/does not work for you and your browser. I tested it in Firefox 3 + Opera 9.63. Chrome is blocked here and MSIE is broken and disabled.


Firefox 3.0.5; Windows XP, worked for me. Cut and pasted the code, perfect formatting. Cut and pasted the highlighted code, perfect single long line of text with no breaks.
Communibus
That’s why I added it. I don’t understand why new lines don’t get pasted when you use style=”white-space: pre;”.
Freaky CSS practices. Only works as it should on Opera.