Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8246927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:40:12+00:00 2026-06-07T22:40:12+00:00

I have a long string that contains a styled tag that I want to

  • 0

I have a long string that contains a styled tag that I want to remove and replace with some other string.
However I’ve tried the str_replace function but it has failed. Any idea how I can do that? My code is here.

$primaryNav = '<li id="menu-item-1178" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1178 sf-ul">
                <a href="http://mysite.com/join/" class="sf-with-ul">
                    <cufon class="cufon cufon-canvas" alt="Get " style="width: 30px; height: 15px; ">
                        <canvas width="45" height="16" style="width: 45px; height: 16px; top: -1px; left: -2px; "></canvas>
                        <cufontext>Get </cufontext>
                    </cufon>
                    <cufon class="cufon cufon-canvas" alt="in" style="width: 15px; height: 15px; ">
                        <canvas width="24" height="16" style="width: 24px; height: 16px; top: -1px; left: -2px; "></canvas>
                        <cufontext>in</cufontext>
                    </cufon>
                    <span class="sf-sub-indicator"><cufon class="cufon cufon-canvas" alt="»" style="width: 6px; height: 15px; "><canvas width="20" height="16" style="width: 20px; height: 16px; top: -1px; left: -2px; "></canvas><cufontext>»</cufontext></cufon></span></a>
                        <ul class="sub-menu" style="visibility: hidden; display: none; "> </ul>
                </li>';

$primaryNav = str_replace('<span class="sf-sub-indicator"><cufon class="cufon cufon-canvas" alt="»" style="width: 6px; height: 15px; "><canvas width="20" height="16" style="width: 20px; height: 16px; top: -1px; left: -2px; "></canvas><cufontext>»</cufontext></cufon></span>', ' It works!', $primaryNav);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:40:13+00:00Added an answer on June 7, 2026 at 10:40 pm

    You need to account for the spaces between tags. This is one case where regular expressions might be a decent solution:

    $primaryNav = preg_replace('#<span class="sf-sub-indicator">\s*<cufon class="cufon cufon-canvas" alt="»" style="width: 6px; height: 15px; ">\s*<canvas width="20" height="16" style="width: 20px; height: 16px; top: -1px; left: -2px; ">\s*</canvas>\s*<cufontext>»</cufontext>\s*</cufon>\s*</span>#', 'It works!', $primaryNav);
    

    The # is used to start/end the regex so you can ignore it. The \s* means match any number of spaces, as many times as you can. This will cover spaces, tabs, linebreaks, etc.

    Note that you can also, using regex, match a lot less if you don’t need as much detail:

    $primaryNav = preg_replace('#<span class="sf-sub-indicator">.*?</span>#', 'It works!', $primaryNav);
    

    Note that this last one will stop matching at the first </span>, so if you have more than one, you’ll need to be careful – regular expressions do not support this kind of ‘balancing’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a long string that contains text. I want to extract every word
I have a simple question. I have a long std::string that I want to
In JavaScript I have a var str = .a long string that contains many
I have a variable that contains a long string that represents an XML document.
I have a string 'sSQL' that contains a very long tsql statement. I need
I have a long string of HTML that contains <p> <img> <span> and a
I have a fairly long string that contains sub strings with the following format:
I have a variable that contains a long string. (specifically it contains a few
I have a data frame that contains a long character string each associated with
We have a unit test with variable that contains a very long string. Question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.