jwhite68 Posted September 18, 2007 Share Posted September 18, 2007 I have used a class called clsMetaContent.php, as provided in the book Creating Interactive Websites with PHP and Web Services, by Eric Rosebrock - who I understand is the lead developer of this site. 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. The code in the class looks like this: // Formulate the description for each page. if(empty($ptitle)){ $description = $this->description; } else { $description = '$ptitle - $this->description"; I have found that my description can contain single and/or double quotes. Which 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 tad description, it outputs the contents of description again on the start of my web page, instead of keeping it within the meta tag assignment. I think I just need a function to strip out double and single quotes - but have been unable to find any. Can anyone offer some advice? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/69758-how-to-strip-quotes-single-and-double-from-a-string-in-php/ Share on other sites More sharing options...
sasa Posted September 18, 2007 Share Posted September 18, 2007 change $description = '$ptitle - $this->description"; to $description = "$ptitle - $this->description"; Quote Link to comment https://forums.phpfreaks.com/topic/69758-how-to-strip-quotes-single-and-double-from-a-string-in-php/#findComment-350472 Share on other sites More sharing options...
jwhite68 Posted September 18, 2007 Author Share Posted September 18, 2007 That was my mistake in the first place, as I was 'playing' with the quotes in this assignment. It was originally with the double quotes as you have shown, and this is when the problem occurs. Quote Link to comment https://forums.phpfreaks.com/topic/69758-how-to-strip-quotes-single-and-double-from-a-string-in-php/#findComment-350473 Share on other sites More sharing options...
Danltn Posted September 18, 2007 Share Posted September 18, 2007 I just need a function to strip out double and single quotes Wouldn't str_replace do this? Quote Link to comment https://forums.phpfreaks.com/topic/69758-how-to-strip-quotes-single-and-double-from-a-string-in-php/#findComment-350476 Share on other sites More sharing options...
sasa Posted September 18, 2007 Share Posted September 18, 2007 Ok try if(empty($ptitle)){ $description = addslashes($this->description); } else { $description = addslashes($ptitle) . ' - ' . addslashes($this->description); Quote Link to comment https://forums.phpfreaks.com/topic/69758-how-to-strip-quotes-single-and-double-from-a-string-in-php/#findComment-350479 Share on other sites More sharing options...
jwhite68 Posted September 18, 2007 Author Share Posted September 18, 2007 I have been trying this without success: // Formulate the description for each page. if(empty($ptitle)){ $description = $this->description; } else { $description = "$ptitle - $this->description"; } $description = str_replace('"', '\"', $description); $description = str_replace("'", "\'", $description); Trying to replace double quote in first str_replace and replace single quote in second. ie. replace with \ so that its escaped, instead of removing it. Quote Link to comment https://forums.phpfreaks.com/topic/69758-how-to-strip-quotes-single-and-double-from-a-string-in-php/#findComment-350484 Share on other sites More sharing options...
jwhite68 Posted September 18, 2007 Author Share Posted September 18, 2007 Sorry, was posting that while you posted your suggestion sasa. I have implemented your suggestion now,and it removes slashes, but I still have an error with meta description. Highlights in red colour (as error) in Firefox. This is what is being assigned: <META NAME="DESCRIPTION" CONTENT="Hillside is offered as a project that encompasses the plan for a 15-unit apartment complex located within 3km from the Albena beach resort and the development site (land plot).<br /><br />The apartments would comprise of studio, 1 and 2 bedrooms, with views over neighbouring hillside. The plan includes 4 levels, one of which is designated to provide recreational facilities such as a gym, cinema room, games room.<br /><br />The concept also incorporates an outdoor swimming pool with bar area.<br /><br />Located in a village that can be reached within 25 minutes from the Varna International Airport, this makes it a very attractive proposition for investors as a key factor for the selection of a rental apartment.<br /><br />With just a 5 minute drive to the very popular Albena beach resort, it is ideally situated for tourists, and can provide additional accommodation for the tourist market.<br /><br />What is even more attractive is that there are two Gary Player designed golf courses under construction – which are within 15 and 30 minutes drive of this "Hillside" development – providing even more recreational facilities. These are known as "BlackSeaRama" and "Thracian Cliffs" and denote signature Gary Player courses.<br /><br />• Architectural plans for the "Hillside" apartment complex<br />• 3D model of the development (3DStudio Max)<br />• Regulated land plot for the development site<br />• Land plot documentation (title deed and building visa – "PUP")<br />• Original brochure template for brochure print runs (advertising material)<br />• 3D photographs of the "Hillside" development<br />• Photographs of the village (for advertising purposes)<br />• "Hillside" logo<br />• "Hillside" advertising material / information pack / marketing style<br />• Colour floor plans for each level<br />• Web site material for advertising the development (HTML files and related images)<br /><br />Please note that individual apartment units are NOT for sale.<br />"> Not sure if its the bullet points thats causing an issue with it. It highlights the content up to Gary player courses in red. Quote Link to comment https://forums.phpfreaks.com/topic/69758-how-to-strip-quotes-single-and-double-from-a-string-in-php/#findComment-350488 Share on other sites More sharing options...
darkfreaks Posted September 18, 2007 Share Posted September 18, 2007 try <?php $description= str_replace("'",''); $description= str_replace('"',''); ?> Quote Link to comment https://forums.phpfreaks.com/topic/69758-how-to-strip-quotes-single-and-double-from-a-string-in-php/#findComment-350491 Share on other sites More sharing options...
jwhite68 Posted September 18, 2007 Author Share Posted September 18, 2007 This seems to have fixed it: // 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); } Quote Link to comment https://forums.phpfreaks.com/topic/69758-how-to-strip-quotes-single-and-double-from-a-string-in-php/#findComment-350502 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.