Information that for display reasons | sharedinfohxのブログ

sharedinfohxのブログ

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

I just this minute had to create a awfully primitive email chief for a patron. It was essential to force whatever paper from a info and afterwards to place that deed into an email message, which was later pink-slipped off to a post list.

The difficulty I had was that the set book contained HTML tags as very well as opposite HTML characters (for example, nbsp;), and I only desirable prairie text in the email.

(Please information that for display reasons in this article, I've omitted the ascendant punctuation from the HTML behaviour.)

Latest instances

I was competent to use the PHP strip_tags mathematical relation to delete the HTML tags (see down below), but this still disappeared me near several HTML characters in the text.

The use of a rhythmical look resolved the catch.

Here is the bit of codification I used to spick-and-span up the list of the variable:

A little pattern

// 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 page of article from the information I situated it in a unfixed called $contents. I after ran the PHP strip_tags drive on the unpredictable to get rid of the HTML tags.

Next we have the bit of symbols that includes the rhythmical exhibition.

$pattern contains the HTML character we poorness to explore for. Here, $pattern contains nbsp;, which is the HTML imaginary creature for a non-breaking abstraction. I required to get rid of this and renew it beside a mundane area because it looked a bit astonishing in the email statement. For example, I needed to change:

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

to:

'this week's privileged tender is...'

$replacement contains a empty space, which is what I impoverishment to replace nbsp; with.

The end line in the bit of belief is the very weak slogan.