SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    UK
    Posts
    539
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Insert string just before every nth <b>

    Hi! I have a string that contains this format:

    HTML Code:
    <b>....</b>
    ......
    
    <b>....</b>
    ......
    etc....

    I'm looking to add a string eg:

    HTML Code:
    <div id="x"></div>
    just before every nth occurence of
    HTML Code:
    <b>
    How can I best achieve this?

  2. #2
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,838
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    With text-editor try replacing <b> with <div id="x"></div><b>

    I have just tried replacing the strig using Sublime text ediror and it works fine.
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014

  3. #3
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    UK
    Posts
    539
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks but this is taking an HTML form input processing and then outputing to screen! I have created the string to be manipulated and need to add in every nth <b> the insert-string

  4. #4
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,838
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by skyline View Post
    Thanks but this is taking an HTML form input processing and then outputing to screen! I have created the string to be manipulated and need to add in every nth <b> the insert-string
    If you are using PHP then try this:
    PHP Code:

    $str 
    "this is a test to see if it works<b>...BOLD...</b>";
    $str .= $str;
    $x '<div id="x"></div><b>';
    $new str_replace('<b>'$x$str);
    echo 
    '<br />';
    echo 
    $new;
    echo 
    '<br />';
    echo 
    '<br />';
    echo 
    highlight_string($new);
    echo 
    '<br />';
    echo 
    '<br />'
    this is a test to see if it works
    ...BOLD...this is a test to see if it works
    ...BOLD...

    this is a test to see if it works<div id="x"></div><b>...BOLD...</b>this is a test to see if it works<div id="x"></div><b>...BOLD...</b>
    Last edited by John_Betong; Mar 10, 2013 at 11:41. Reason: added output
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •