Jump to content

rpmorrow

Members
  • Posts

    27
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

rpmorrow's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Rather than counting characters from your occurrence of "Neighborhood:", use a combination of strpos and substr to find the position of the next font tag and then insert what you need using preg_replace, or str_replace.
  2. Thank you very much. It's all working great and my code is much simpler I had a look around about the buffering, it all looks quite interesting. I'm sure I will be using it more in future. Thanks again.
  3. Cool, that seems to be working! $_GET is working too!! To do the replacing repeatedly, I'm doing the following, its working but it feels so strange to do it like this (I never even heard of buffering the output like this b4 now). Is it ok? $output = preg_replace("/~~FIRSTTHING~~/",$row['first'],ob_get_clean(),1); $output = preg_replace("/~~SECONDTHING~~/",$row['second'],$output,1); $output = preg_replace("/~~THIRDTHING~~/",$row['third'],$output,1); echo $output; $output = preg_replace("/~~LASTTHING~~/",$row['last'],ob_get_clean(),1); echo $output;
  4. If I'm using file_get_contents(), it does not parse the PHP code, so when I go view-source, it looks as below. I've put the various code segments below. Example of template code (I've removed all the html header etc for simplicity): <div id="content"> <div id="leftColumn"> ~~LEFTMENU~~ <? include_once($_SERVER['DOCUMENT_ROOT'].'/includes/box-left.inc.php'); ?> </div> <div id="rightColumn"> <? include_once($_SERVER['DOCUMENT_ROOT'].'/includes/box-right.inc.php'); ?> </div> ~~PAGECONTENT~~ <? include_once($_SERVER['DOCUMENT_ROOT'].'/includes/searchresult.inc.php'); ?> </div> <div id="footer"> <? include_once($_SERVER['DOCUMENT_ROOT'].'/includes/footer.inc.php'); ?> </div> /includes/searchresult.inc.php <? $searchQuery = $_GET['q']; echo $searchQuery; //was empty ?> The code to replace ~~PAGECONTENT~~ etc is in functions.inc.php (simplified) <? function DisplayPage($page_id, $page_type) { //the two variables here are used to select the right info from database, and which template to use $template_html = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/templates/home-template.htm'); $parsed_html = preg_replace("/~~PAGECONTENT~~/",$row['page_content'],$template_html,1); echo $parsed_html; ?> The file visited by the user www.example.com/search.php?q=something <? include_once('includes/functions.inc.php'); DisplayPage("Search", "search"); //page_id, page_type ?> P.S. I'm using the code button in the forum, but it is not colouring the php for u, I need add something else?
  5. Thanks, I had tried using that but the includes in the template stop working. I'm calling them in the template as follows.. <? include_once($_SERVER['DOCUMENT_ROOT'].'/includes/menu-top.inc.php'); ?>
  6. I am using curl because I need to str_replace data in the template. I didn't know it would be slow.. hmm, maybe i should look at another approach for this
  7. You need to make a while loop that generates the html table rows. Example... <?php while ($row = mysql_fetch_assoc($result) ) { echo "<tr><td>".$row['name']."</td></tr>"; } ?>
  8. 1. Yes, FALSE is fine, or you could have NULL or... return ""; They are equivalent, but are NOT identical. (See if ===) 2. you can have return multiple times in a function because only one of them can ever call at once. As soon as whatever conditions you set executes the first "return" then the function is finished and any others are irrelevant at that time.
  9. Yes you can! Just adding "AddType x-mapp-php5 .html .htm" to the .htaccess file does it.
  10. I am trying to make a site with content in databases and using some template html files for the layout. The problem I am having is that the code is executing in the template directory and can't therefore read the value from any $_GET that is on the url used by the user. I hope you can understand my meaning. Let me give an example of the structure.. The user visits "www.example.com/search.php?q=something" The file "search .php" just contains a function call to display the page; e.g. DisplayPage("search"); The DisplayPage function uses CURL to read the contents of a HTML file (/templates/search-template.htm) into a string. It then uses preg_replace and str_replace to replace some markers that are in the template, with data from the database. At the end of the function it simply echoes the string. The template files contain some includes, which work fine, but the code executing within them "thinks" it is being executed from /templates/search-template.htm rather than /search.php. Therefore if I use $_GET['q'] in any of those includes, it is empty. I hope that makes sense! Is there any way for me to make the executing code work as if it is being executed from "/search.php" rather than the template?
  11. Hi, I try to execute the code below but I get the error "Cannot instantiate non-existent class: mysqli" so I assume it is not supported by my host. Is there an equivalent command I can use? (php5 not supported either) $dbh = new mysqli($db_host,$db_user,$db_pass,$db_name);
  12. Your query needs to use $_POST['dropdown'] instead of $dropdown
  13. Hi, I'm trying to create a menu such as an unordered list based on info in a single SQL table. I've seen examples of using LEFT OUTER JOIN to do it, but this seems to involve multiple tables and I just get an error if I try it with one table. The columns are as follows; id parent_id title 1 0 Some words 2 0 Some words2 3 2 Some words3 4 2 Some words4 5 3 Some words5 I want it to return the following; Some words Some words2 Some words3 Some words5 Some words4 Can anyone point me to an example?
×
×
  • 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.