Jump to content

Why does nbsp; cause an issue in text for assignment to meta content description


jwhite68

Recommended Posts

I have used a class called clsMetaContent.php, as provided in the book Creating Interactive Websites with PHP and Web Services, by  Eric Rosebrock.

 

While using this class with my application - I find a problem in the assignment of the description for the description part of the meta tag (similar to an earlier post of mine).

 

The code in the class now looks like this (revised after earlier post):

 

 

// Formulate the description for each page.
     $this->description = strip_tags($this->description);
      if(empty($ptitle)){
        $description = addslashes($this->description);
     } else {
       $description = addslashes($ptitle) . ' - ' . addslashes($this->description);
 }

 

I have found that if description contains the text "nbsp;" it causes a problem with the assignment of the meta tag for the description. What happens is, due to the error in the format of the meta tag description, it outputs the contents of description again on the start of my web page, instead of keeping it within the meta tag assignment.

 

Can anyone offer some advice? I dont understand why this string would cause the meta content description to be assigned incorrectly.

 

Thanks in advance.

 

Link to comment
Share on other sites

I assign the description (from my clients data) to the META content.  I do strip out HTML, but the source content is perhaps poor.

 

So I didnt choose to put &nbsp in there. It was in my clients data.  This is the problem accepting data in files from clients, because you cannot always rely on its integrity.

 

The source text I got from a file is:

 

<H1 style="BACKGROUND: white; MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 24.0pt"> </SPAN><SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt">IBAR Palace – Key Points</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 24.0pt"><o:p></o:p></SPAN></H1>
<UL type=disc>
<LI class=MsoNormal style="BACKGROUND: white; MARGIN: 0cm 0cm 0pt; COLOR: black; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 8.5pt">1x 1 Sudio apartment</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 8.5pt"><o:p></o:p></SPAN> 
<LI class=MsoNormal style="BACKGROUND: white; MARGIN: 0cm 0cm 0pt; COLOR: black; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 8.5pt">1</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 8.5pt">2</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 8.5pt"> x 2 Double bedroom apartments<o:p></o:p></SPAN> 
<LI class=MsoNormal style="BACKGROUND: white; MARGIN: 0cm 0cm 0pt; COLOR: black; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 8.5pt">12 x 1 Double bedroom apartments<o:p></o:p></SPAN> 
<LI class=MsoNormal style="BACKGROUND: white; MARGIN: 0cm 0cm 0pt; COLOR: black; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 8.5pt">All apartments with </SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt">magnificent </SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt">mountain </SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt">views</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 8.5pt"><o:p></o:p></SPAN> 
<LI class=MsoNormal style="BACKGROUND: white; MARGIN: 0cm 0cm 0pt; COLOR: black; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 8.5pt">Healthy old-pine wood surrounding<o:p></o:p></SPAN> 
<LI class=MsoNormal style="BACKGROUND: white; MARGIN: 0cm 0cm 0pt; COLOR: black; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 8.5pt">Gothic style of building</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt">   </SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 8.5pt"><o:p></o:p></SPAN>
<LI class=MsoNormal style="BACKGROUND: white; MARGIN: 0cm 0cm 0pt; COLOR: black; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt">Italian bathrooms</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 8.5pt"><o:p></o:p></SPAN> 
<LI class=MsoNormal style="BACKGROUND: white; MARGIN: 0cm 0cm 0pt; COLOR: navy; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt">Ski depot, </SPAN><SPAN style="FONT-SIZE: 11pt; COLOR: windowtext; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt">Lobby</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; COLOR: windowtext; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt"> with Fireplace</SPAN><SPAN style="FONT-SIZE: 11pt; COLOR: windowtext; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt">, Restaurant, Fitness, Sauna</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; COLOR: windowtext; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt">, Billiards, Laundry</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 8.5pt"><o:p></o:p></SPAN> 
<LI class=MsoNormal style="BACKGROUND: white; MARGIN: 0cm 0cm 0pt; COLOR: black; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt">Shared parking</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 8.5pt"><o:p></o:p></SPAN></LI></UL>
<P class=MsoNormal style="BACKGROUND: white; MARGIN: 0cm 0cm 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt">The apartments benefit from double glazed windows, local heating, </SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt">Italian </SPAN><SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt">terracotta tiling in the bathrooms, parquet</SPAN><SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt"> </SPAN><SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt">or rug floors in the bedrooms</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt"> (according to the customer’s requirements)</SPAN><SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt">, </SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt">laundry service, </SPAN><SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt">a one car parking lot for each house, lobby, restaurant, fitness and sauna to the highest standards. <BR></SPAN><SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt"><BR>The <STRONG>annual maintenance fee</STRONG>, which will cover the cleaning, upkeep and lighting of the common areas, maintenance of the fitness </SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt">and sauna</SPAN><SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt">, 24 hours security services and use of the laundry mat.</SPAN><SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt"> </SPAN><SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt">The annual fee will be approximately 500?. <BR></SPAN><SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt"><BR>Living area for</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt"> the</SPAN><SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt"> apartment</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt">s</SPAN><SPAN style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.0pt"> will be from 30.83 to 71 sq.m. <BR></SPAN><FONT face=Arial><SPAN lang=EN-US style="FONT-WEIGHT: normal; FONT-SIZE: 11pt; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt"><BR>The new development is attached to the well known </SPAN><SPAN style="FONT-WEIGHT: normal; FONT-SIZE: 11pt; mso-bidi-font-size: 10.0pt">Ibar hotel which has always been known for good accommodation and reasonable price. <BR></SPAN></FONT><FONT face=Arial><SPAN lang=EN-US style="FONT-WEIGHT: normal; FONT-SIZE: 11pt; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt">The seasonal booking for accommodation in the new apartments is estimated at 75% occupancy during the winter months. At least </SPAN><SPAN style="FONT-SIZE: 11pt; mso-bidi-font-size: 10.0pt">8% </SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt">is </SPAN><SPAN style="FONT-SIZE: 11pt; mso-bidi-font-size: 10.0pt"><STRONG>Guaranteed Rental Income per </STRONG></SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; mso-ansi-language: EN-US; mso-bidi-font-size: 10.0pt"><STRONG>Year</STRONG>.<BR></SPAN></FONT><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt"><BR>Advanced skiers and experts can enjoy one of the more challenging </SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt">slopes</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt"> in Borovetz </SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt"><SPAN style="mso-spacerun: yes"> </SPAN>- </SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt">the testing World Cup run 60m from IBAR </SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt">Palace</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt">. Also the b</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt">lack runs of Markoudzhik 1 and 2</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt"> or the excellent skiing through the trees and off-tracks. <BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">Annual competition and </SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-ansi-language: EN-GB; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">regular demonstrations during the ski season take place on the ski</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"> jumping track some 150m from IBAR Palace.</SPAN>  </P>

 

But some post processing is done on this, which is also failing.  The post processing is:

 

$sRecDesc = strip_tags($sRecDesc,'<ul><li><br>') 			
$sRecDesc = nl2br($sRecDesc);

 

I leave just ul,li and br tags in clients data to at least keep any basic format info, such as bullets and line breaks.

 

But after this code, the output looks like this:

 

nt-size: 10.0pt">apartments development consists of 15 one and two bedroom apartments ideally located in the famous Borovetz ski resort just 100m away from the best ski slope for advanced skiers. All apartments have magnificent mountain views to an old pine forest. Approx. 40% of them is already sold to UK citizens.  IBAR Palace – Key Points 1x 1 Sudio apartment 12 x 2 Double bedroom apartments 12 x 1 Double bedroom apartments All apartments with magnificent mountain views Healthy old-pine wood surrounding Gothic style of building   Italian bathrooms Ski depot, Lobby with Fireplace, Restaurant, Fitness, Sauna, Billiards, Laundry Shared parking The apartments benefit from double glazed windows, local heating, Italian terracotta tiling in the bathrooms, parquet or rug floors in the bedrooms (according to the customer’s requirements), laundry service, a one car parking lot for each house, lobby, restaurant, fitness and sauna to the highest standards. The annual maintenance fee, which will cover the cleaning, upkeep and lighting of the common areas, maintenance of the fitness and sauna, 24 hours security services and use of the laundry mat. The annual fee will be approximately 500?. Living area for the apartments will be from 30.83 to 71 sq.m. The new development is attached to the well known Ibar hotel which has always been known for good accommodation and reasonable price. The seasonal booking for accommodation in the new apartments is estimated at 75% occupancy during the winter months. At least 8% is Guaranteed Rental Income per Year.Advanced skiers and experts can enjoy one of the more challenging slopes in Borovetz  - the testing World Cup run 60m from IBAR Palace. Also the black runs of Markoudzhik 1 and 2 or the excellent skiing through the trees and off-tracks. Annual competition and regular demonstrations during the ski season take place on the ski jumping track some 150m from IBAR Palace.   apartments development consists of 15 one and two bedroom apartments ideally located in the famous Borovetz ski resort just 100m away from the best ski slope for advanced skiers. All apartments have magnificent mountain views to an old pine forest. Approx. 40% of them is already sold to UK citizens.  IBAR Palace – Key Points 1x 1 Sudio apartment 12 x 2 Double bedroom apartments 12 x 1 Double bedroom apartments All apartments with magnificent mountain views Healthy old-pine wood surrounding Gothic style of building   Italian bathrooms Ski depot, Lobby with Fireplace, Restaurant, Fitness, Sauna, Billiards, Laundry Shared parking The apartments benefit from double glazed windows, local heating, Italian terracotta tiling in the bathrooms, parquet or rug floors in the bedrooms (according to the customer’s requirements), laundry service, a one car parking lot for each house, lobby, restaurant, fitness and sauna to the highest standards. The annual maintenance fee, which will cover the cleaning, upkeep and lighting of the common areas, maintenance of the fitness and sauna, 24 hours security services and use of the laundry mat. The annual fee will be approximately 500?. Living area for the apartments will be from 30.83 to 71 sq.m. The new development is attached to the well known Ibar hotel which has always been known for good accommodation and reasonable price. The seasonal booking for accommodation in the new apartments is estimated at 75% occupancy during the winter months. At least 8% is Guaranteed Rental Income per Year.Advanced skiers and experts can enjoy one of the more challenging slopes in Borovetz  - the testing World Cup run 60m from IBAR Palace. Also the black runs of Markoudzhik 1 and 2 or the excellent skiing through the trees and off-tracks. Annual competition and regular demonstrations during the ski season take place on the ski jumping track some 150m from IBAR Palace.  ">

 

So, you see, there is more than one issue at stake.

 

The above output is then ran through as this->description for the meta content, which is causing a problem in the assignment.

 

So to begin with, need to solve another issue to get the data stripped out properly, since thats obviously not working for some reason.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.