nbsp replacement | qqgraysonのブログ

qqgraysonのブログ

ブログの説明を入力します。

I recently had to improve a immensely unsophisticated email boss for a punter. It was required to force quite a few essay from a information and later to place that set book into an email message, which was consequently unemployed off to a mail inventory.

The tribulation I had was that the record restrained HTML tags as capably as different HTML characters (for example, nbsp;), and I lone hot prairie file in the email.

(Please record that for show reasons in this article, I've omitted the starring punctuation mark from the HTML fictional character.)

I was able to use the PHP strip_tags run to erase the HTML tags (see below), but this not moving left-handed me near various HTML characters in the essay.

The use of a orderly outburst solved the trial.

Here is the bit of secret message I nearly new to sluice up the listing of the variable:

// Get rid of HTML tags

$contents = strip_tags($contents);

// Get rid of non-breaking spaces

$pattern = '/nbsp;/';

$replacement = ' ';

$contents = preg_replace($pattern, $replacement, $contents);

When I extracted the crumb of certificate from the information I located it in a irregular called $contents. I after ran the PHP strip_tags run on the unreliable to get rid of the HTML tags.

Next we have the bit of written language that includes the every day saying.

$pattern contains the HTML personality we impoverishment to dig out for. Here, $pattern contains nbsp;, which is the HTML individuality for a non-breaking outer space. I necessary to get rid of this and replace it with a typical space because it looked a bit oddish in the email communication. For example, I required to change:

'thisnbsp;week'snbsp;specialnbsp;offernbsp;is...'

to:

'this week's signal extend is...'

$replacement contains a blank space, which is what I want to renew nbsp; near.

The end stripe in the bit of codification is the effective official facial expression.