Forum Moderators: coopster
I have an xml feed I've parsed and not I have a very messy string. I'm trying to delete pieces of the string that contain links and other unnecessary content.
How do I remove say links within a string using regex or any other method.
example string:
Search: Title Ingredients Category: Recipes ¦ Miscellaneous ¦ Dressings ¦ Dill Dressing Green Goddess Dressing Login Photos for this Recipe: 0 Photos Add Your Recipe Photo Recipe Tools: Add to My Cookbook Email this Recipe Print this Recipe Review this Recipe Submit your Recipe Scale & Convert Recipe: Scale to recipe U.S. / Imperial Metric Decimal Fraction Epicurean Resources: Conversion Table Discussion Board Food and Wine Pairing Food Encyclopedia Kitchen Products Orlando Culinary Institute Wine for Newbies Foodgeek: malooga Rating: Servings: 1 recipe Prep. Time: Total Time: Ingredients: 1/2 cup chopped green onions 1/4 cup chopped fresh Italian (flat-leaf) parsley 1 clove garlic 1 tbsp. fresh tarragon 1 tbsp. fresh dill 1 tbsp. red wine vinegar 1/2 cup buttermilk Salt and freshly ground black pepper 1-1/2 tsp. granulated sugar 1/2 cup sour cream or plain yogurt Directions: In a food processor or blender, purée the green onions, parsley, garlic, tarragon and dill. Add the vinegar, buttermilk, 1½ teaspoons salt, ¼ teaspoon pepper and the sugar. Transfer to a bowl and fold in the sour cream or yogurt (this keeps the dressing from getting too thin). User Reviews: 0 user reviews. Add your review of this recipe. Home ¦ Recipes ¦ Food Encyclopedia ¦ Diets ¦ Resources ¦ Discussion ¦ Geeks ¦ About All rights reserved. Privacy Policy
I want to remove those menu links and footer links. They are wrapped in <a href=""> tags.
$string = preg_replace('/<\/*[^>]+>/igm','',$string);
< - starts with <
\/* followed by zero or more /, escaped (catches both opening and closing tags)
[^>]+ - followed by one or more of any character not a >
> ending with >
igm - case insensitive, apply it globally, treat the string as multiple lines (if it errors, it means PHP doesn't support the multiline modifer, but I think it does. Old Timer's disease, you know . . .)