SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast guitarnoise's Avatar
    Join Date
    Nov 2002
    Location
    Southeast Asia
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    is strlen the right thing to use

    Hi,
    I'm trying to stick an ad a few paragraphs into articles on my site like you see sometimes on news websites. I was able to do it using strlen and splitting the article text in two. But it's kind of messy. The code I wrote isn't flexible enough for me, and if the chracters in the article that get the split happen to be part of an image tage the article is ruined. Is there a better way to have an ad appear a few paragraphs into an article and then have the article continue below the ad?

  2. #2
    One website at a time mmj's Avatar
    Join Date
    Feb 2001
    Location
    Melbourne Australia
    Posts
    6,282
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You would need to parse the article so that the program knows where the breaks between paragraphs are.

    Is the article in some sort of XML-compatible format? I just mention this because parsing would be easier with domxml.
    [mmj] My magic jigsaw
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The Bit Depth Blog Twitter Contact me
    Neon Javascript Framework Jokes Android stuff

  3. #3
    SitePoint Enthusiast guitarnoise's Avatar
    Join Date
    Nov 2002
    Location
    Southeast Asia
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The article format just uses very basic html. Not sure if that is compatible with domxml. What you're saying is I can parse for all the paragraph breaks and have php insert something the second or third time a break appears. Is that correct? I know I could go back an insert something manually but I have over 450 articles.

  4. #4
    One website at a time mmj's Avatar
    Join Date
    Feb 2001
    Location
    Melbourne Australia
    Posts
    6,282
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I think what you could do is do a search for </p> tag. Then, please the ad inside another paragraph and insert it after that </p> tag.

    A simple strpos should find the </p> tag, or you could do an explode and count the paragraphs.
    [mmj] My magic jigsaw
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The Bit Depth Blog Twitter Contact me
    Neon Javascript Framework Jokes Android stuff

  5. #5
    SitePoint Enthusiast guitarnoise's Avatar
    Join Date
    Nov 2002
    Location
    Southeast Asia
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A strpos would find the first </p> right? How would I use explode to get a string other than the first one. I'm kind of new to programming and if someone could help me with a little example that would probably be the easiest way to help me.

    Thanks.
    Last edited by guitarnoise; Jul 24, 2004 at 09:21.


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
  •