I lately had to develop a precise natural email checker for a client. It was needed to quotation a number of text from a info and afterwards to insert that workbook into an email message, which was afterwards discharged off to a mail record.

The hassle I had was that the set book restrained HTML tags as capably as other HTML characters (for example, nbsp;), and I just considered necessary lowland workbook in the email.

(Please details that for fair reasons in this article, I've omitted the overriding punctuation mark from the HTML persona.)

Full examples:

I was able to use the PHP strip_tags activate to take out the HTML tags (see beneath), but this static leftmost me beside various HTML characters in the article.

The use of a stock torrent solved the catch.

Here is the bit of attitude I in use to unspotted up the table of the variable:

Most recent pieces:

// 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 piece of paper from the information I placed it in a unreliable titled $contents. I consequently ran the PHP strip_tags mathematical relation on the changeable to get rid of the HTML tags.

Next we have the bit of written language that includes the orderly revelation.

$pattern contains the HTML personality we want to survey for. Here, $pattern contains nbsp;, which is the HTML traits for a non-breaking universe. I needed to get rid of this and renew it beside a natural outer space because it looked a bit other in the email communication. For example, I needful to change:

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

to:

'this week's privileged proffer is...'

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

The second stripe in the bit of code is the very rule-governed turn of phrase.

arrow
arrow
    全站熱搜

    ljtallen 發表在 痞客邦 留言(0) 人氣()