Jump to content

Recommended Posts

I am primarily a designer, not a developer, so be gentle. I am using a simple php include for small section on the home page of a golf site entitled "Tournament News."

[code]<?php include ($_SERVER['DOCUMENT_ROOT'].'/news/index.php'); ?>[/code]

However, I would only like to include the "headline" from the page.

[code]<h3>This is a headline</h3>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus fermentum laoreet mauris. Fusce augue nibh, vestibulum id, fringilla a, aliquet sit amet, ante. Etiam ut mauris. In neque quam, adipiscing ut, ultricies sit amet, sodales at, turpis. Ut sit amet enim eget libero malesuada congue. Nullam ac mi quis enim scelerisque venenatis. Proin sollicitudin magna sed dolor. Quisque iaculis cursus diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Pellentesque malesuada risus luctus magna. Sed consectetuer.</p>

<h3>This is a another headline</h3>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus fermentum laoreet mauris. Fusce augue nibh, vestibulum id, fringilla a, aliquet sit amet, ante. Etiam ut mauris. In neque quam, adipiscing ut, ultricies sit amet, sodales at, turpis. Ut sit amet enim eget libero malesuada congue. Nullam ac mi quis enim scelerisque venenatis. Proin sollicitudin magna sed dolor. Quisque iaculis cursus diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Pellentesque malesuada risus luctus magna. Sed consectetuer.</p>

<h3>This is a different headline</h3>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus fermentum laoreet mauris. Fusce augue nibh, vestibulum id, fringilla a, aliquet sit amet, ante. Etiam ut mauris. In neque quam, adipiscing ut, ultricies sit amet, sodales at, turpis. Ut sit amet enim eget libero malesuada congue. Nullam ac mi quis enim scelerisque venenatis. Proin sollicitudin magna sed dolor. Quisque iaculis cursus diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Pellentesque malesuada risus luctus magna. Sed consectetuer.</p>
[/code]

Is there anyway I can pull just the <h3> tags and not the <p> tags?
IS the HTML hard coded in to index.php or is the content comming from a database? If its from a database just query the database to fetch the title for the news articled in the database. If its hard coded I would recommend you to use a database to store the news entries rather than hard coding them in.
jwk811: If I can't get this to work, then that will be my solution, but it will be simpler for my client to update if they are on the same page.

wildteen88: I am setting up this page for a HTML novice to update on occasion. He knows enough to add an <h3> tag to a headline and a <p> tag to the text. It's really such a small part of the site (and temporary) that I was hoping for a fix on the server side to make it easy for him to update.
It would be a lot easier for your customer/end user to fill in a form which will allow him/her to enter the title for the news article and then a small textarea for the news articles content, then from there you could save to an SQL database/flat file. Rather than getting them to edit index.php to add in a news article.
[quote author=wildteen88 link=topic=121392.msg499071#msg499071 date=1168195674]
It would be a lot easier for your customer/end user to fill in a form which will allow him/her to enter the title for the news article and then a small textarea for the news articles content, then from there you could save to an SQL database/flat file. Rather than getting them to edit index.php to add in a news article.
[/quote]

I see where you are coming from, but I'm not really prepared for that either. At most, I'm expecting a total of 10 news items for the entire event. I was just hoping if there was a function that would check the page and write only a specific part of it.
Hey man, try this:
[code]
ob_start();
  include ($_SERVER['DOCUMENT_ROOT'].'/news/index.php');
  if( ob_get_length()>0 )
  {
          $contents = ob_get_clean();
          $match = preg_match('@<h3.*?>(.*?)</h3>@i',$contents,$matches);
          if( $match )
          {
                  echo $headline = $matches[1];
          }
   }
[/code]
[quote author=ShogunWarrior link=topic=121392.msg499105#msg499105 date=1168201147]
Hey man, try this:
[code]
ob_start();
  include ($_SERVER['DOCUMENT_ROOT'].'/news/index.php');
  if( ob_get_length()>0 )
  {
          $contents = ob_get_clean();
          $match = preg_match('@<h3.*?>(.*?)</h3>@i',$contents,$matches);
          if( $match )
          {
                  echo $headline = $matches[1];
          }
  }
[/code]

[/quote]

Thanks, ShogunWarrior, that works.

It only pulls the first headline however. Where would I put a for_each statement, or is that applicable?
[code]
ob_start();
  include ($_SERVER['DOCUMENT_ROOT'].'/news/index.php');
  if( ob_get_length()>0 )
  {
          $contents = ob_get_clean();
          $match = preg_match_all('@<h3.*?>(.*?)</h3>@i',$contents,$matches);
          if( $match )
          {
                  foreach( $matches[1] as $match )
                  {
                          echo $headline = $match;
                  }
          }
  }
[/code]

Didn't test it.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.