www.webdeveloper.com
Results 1 to 3 of 3

Thread: Inserting 'Something' Into A String

  1. #1
    Join Date
    Sep 2008
    Posts
    260

    Inserting 'Something' Into A String

    Hello everyone..

    Let's say I have this

    PHP Code:
    $string '<a>some text</a><a>some text</a><a>some text</a>'
    And I want to insert a <div> tag before every anchor tag and a </div> after every close anchor tag. Is this possible in PHP? (I'm coming from JavaScript)..

  2. #2
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,270
    My first choice would be to just use CSS to display the A elements as blocks.

    Not knowing just what sort of HTML you will be tinkering with, my second choice would be to use DOMDocument. HTML has way too many ins and outs to just manipulate the string. See http://php.net/manual/en/class.domdocument.php .

    But if the HTML really is a simple as the example you have given then just use str_replace. See http://us.php.net/manual/en/function.str-replace.php .
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  3. #3
    Join Date
    Sep 2008
    Posts
    260
    Thanks a lot...this give me some direction..

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles