Squirrels Posted January 7, 2007 Share Posted January 7, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/33228-problem-including-only-specific-content-in-php-include/ Share on other sites More sharing options...
jwk811 Posted January 7, 2007 Share Posted January 7, 2007 would it be possible for you to just make a separate file for the header? and then include that on every page? Quote Link to comment https://forums.phpfreaks.com/topic/33228-problem-including-only-specific-content-in-php-include/#findComment-155116 Share on other sites More sharing options...
wildteen88 Posted January 7, 2007 Share Posted January 7, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/33228-problem-including-only-specific-content-in-php-include/#findComment-155117 Share on other sites More sharing options...
Squirrels Posted January 7, 2007 Author Share Posted January 7, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/33228-problem-including-only-specific-content-in-php-include/#findComment-155118 Share on other sites More sharing options...
wattsup88 Posted January 7, 2007 Share Posted January 7, 2007 i would say that a database is not a "quick fix" so i would go with jwk811's advice on this one... Quote Link to comment https://forums.phpfreaks.com/topic/33228-problem-including-only-specific-content-in-php-include/#findComment-155120 Share on other sites More sharing options...
wildteen88 Posted January 7, 2007 Share Posted January 7, 2007 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 Link to comment https://forums.phpfreaks.com/topic/33228-problem-including-only-specific-content-in-php-include/#findComment-155121 Share on other sites More sharing options...
Squirrels Posted January 7, 2007 Author Share Posted January 7, 2007 [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. Quote Link to comment https://forums.phpfreaks.com/topic/33228-problem-including-only-specific-content-in-php-include/#findComment-155122 Share on other sites More sharing options...
wattsup88 Posted January 7, 2007 Share Posted January 7, 2007 what downside would there be to including the heading and the rest of the page separate would there be? Quote Link to comment https://forums.phpfreaks.com/topic/33228-problem-including-only-specific-content-in-php-include/#findComment-155146 Share on other sites More sharing options...
ShogunWarrior Posted January 7, 2007 Share Posted January 7, 2007 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 Link to comment https://forums.phpfreaks.com/topic/33228-problem-including-only-specific-content-in-php-include/#findComment-155153 Share on other sites More sharing options...
Squirrels Posted January 7, 2007 Author Share Posted January 7, 2007 [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? Quote Link to comment https://forums.phpfreaks.com/topic/33228-problem-including-only-specific-content-in-php-include/#findComment-155340 Share on other sites More sharing options...
ShogunWarrior Posted January 9, 2007 Share Posted January 9, 2007 [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. Quote Link to comment https://forums.phpfreaks.com/topic/33228-problem-including-only-specific-content-in-php-include/#findComment-156779 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.