Tag Archives: strip

Joke Factory: But You Can Leave Your Hat On Jokes & other Funny Stuff 21 OCT 2011

A successful rancher died and left everything to his devoted wife. She was determined to keep the ranch, but knew very little about ranching, so she placed an ad in the newspaper for a ranch hand.

Two cowboys applied for the job. One was gay and the other a drunk.

She thought long and hard about it, and when no one else applied she decided to hire the gay cowboy, figuring it would be safer to have him around the house than the drunk.

He proved to be a hard worker who put in long hours every day and knew a lot about ranching. For weeks the two of them worked hard and the ranch was doing very well.

Then one day, the widow said to the cowboy, “You have done a seriously excellent job – the ranch looks great and things really couldn’t be going any better. You should definitely go into town and kick up your heels for a bit, you deserve it!”

The hired hand readily agreed and so went into town on Saturday night.

He returned around 2:30 am, and upon entering the house, he found the widow sitting by the fireplace with a glass of wine, waiting for him.

She quietly called him over to her.

“Unbutton my blouse and take it off,” she said.

Trembling, he did as she directed.

“Now take off my boots.” He did as she asked, ever so slowly.

“Now take off my socks.” He removed each gently and placed them neatly by her boots.

“Now take off my skirt.” He slowly unbuttoned it, constantly watching her eyes in the fire light.

“Now take off my bra.” Again, with trembling hands, did as he was told and dropped it to the floor.

Then she looked at him square in the eyes and said: “If you ever wear my clothes into town again, you’re fired!”

PHP: How to Remove or Replace Strings from the Front and End of a Value CodeUnit 02 JUL 2010

Today’s little PHP hint is a pretty simple one, but one worth tackling if you are looking for a quick and easy way to strip a particular string pattern off the front and end of a value.

What we will make use of is of course PHP’s built in preg_replace functionality, basically one of the wrapper functions that brings regular expression manipulation to PHP.

Now to start off, we need to specify the string pattern we wish to search for off the front of our value. To do this we make use of the ^ regex control character that denotes the search to begin from the start of a string. To locate a string pattern off the end of our value, we make use of the $ regex control character which likewise, tells the search to commence at the back of the given string value.

We then place our two patterns in a search array, before moving on to define our replace array. Now at this stage you can choose: if you want to simply strip these patterns off the value, then simply match the search patterns with the same amount of blank string values, otherwise insert the string values you wish to replace the patterns with.

Finally, we call the preg_replace function, feeding it our search and replace arrays, as well as the input value it is to work on.

In other words, we would have something like this:

$search = array ( "/^stringatstart /","/ stringatend$/");
$replace = array ('','');

echo preg_replace($search, $replace, "stringatstart Hello World! stringatend");

And there you go, a nice and simple way to strip off specific values at either end of a string! :)