regex or str replace

Posted on 2012-09-04
Last Modified: 2012-09-04
I am using php
want to use regex or maybe str_replace

Text: "Business & Industrial > Heavy Machinery > Chippers"
XML: Business & Industrial > Heavy Machinery > Chippers

"Business & Industrial > Heavy Machinery > Chippers"
want this as output
Business & Industrial > Heavy Machinery > Chippers
Question by:rgb192
    LVL 10

    Accepted Solution

    This should work.  Obviously, substitute your specific variables.

    $str     = "Business & Industrial > Heavy Machinery > Chippers";
    $order   = array("&",">");
    $replace = array("&",">");

    $newstr = str_replace($order, $replace, $str);

    Note: the sequence of the $order and $replace arrays is important.  If you reverse the "&" and ">" replacement pairs, you would end up with the following (undesired) result:

    Business & Industrial > Heavy Machinery > Chippers

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now