0

Hi,

I am using str_replace to scan through pages and replace, for example; [gallery] with the actual gallery page using an include command.

For example;

[gallery]

Once this is located it's replaced by
include('modules/gallery/index.php');

How can you do this (and for multiple ones, [gallery], [enquiry]?

Thank's very much.
Zack.

6
Contributors
20
Replies
22
Views
7 Years
Discussion Span
Last Post by Froger93
0

str_replace is for strings. I don't think you can replace it with php commands as it would be placed in a string container.

0

What command would i need to replace with php code?

Kind regards,
Zack.

0
$str1 = array('[gallery]','[enquiry]');
$str2 = "include('modules/gallery/index.php');";
str_replace($str1, $str2, $target);

This will do the same for you, provided $target is the target string inside which you want to do the replacement.
try to escape the '/' inside the string if it troubles

0

Hi,

This is the current code concept i have come up with:

$code  = $pager['code'];
	$block = array("[gallery]", "[enquiry]");	
	$replace   = array("include('modules/gallery/index.php')", "include('modules/enquiry/index.php')");
	$replaced_code = str_replace($block, $replace, $code);
	echo $replaced_code;

Say i use the [gallery] tag, it just displays;

include('modules/gallery/index.php')

Zack

Edited by Zack_G: n/a

0
<?php

 $file_path = "gallery/index.php";
 
 /* First Include Gallery Module */
 
 include ($file_path);
  
 /* Replace Gallery Module to Enquiry Module */

 $file_path = str_replace("gallery","enquiry",$file_path);
 
 /* First Include Gallery Module */
 
  include ($file_path);

 
?>
0
<?php

 $file_path = "gallery/index.php";
 
 /* First Include Gallery Module */
 
 include ($file_path);
  
 /* Replace Gallery Module to Enquiry Module */

 $file_path = str_replace("gallery","enquiry",$file_path);
 
 /* First Include Gallery Module */
 
  include ($file_path);

 
?>
0

Hiya,

Bit confused, how would that include the enquiry php file for [enquiry] and the gallery php file for [gallery]?

Thanks
Zack

0

Hi Network18,

The code i provided does not work. It just displays include('filepath'); on the webpage, it does not include the file.

Zack

0

You would need to run the new string through eval to make the includes work.

Use that function with caution though. If you don't use it right there are huge security risks.

0

You would need to run the new string through eval to make the includes work.

Use that function with caution though. If you don't use it right there are huge security risks.

0
<?php

 $file_path = "modules/gallery/index.php";
 
 include ($file_path);
 
 $file_path = str_replace("gallery","enquiry",$file_path);
 
 include ($file_path);
 
?>
0
<?php

 $file_path = "modules/gallery/index.php";
 
 include ($file_path);
 
 $file_path = str_replace("gallery","enquiry",$file_path);
 
 include ($file_path);
 
?>
0

Is [GALLERY] inside <?php ?> tags?

I would manually code the include where you want.

One way would to be use authoring software like DW to search and replace [GALLERY] with <?php include("gallery/index.php"); ?>

also kkeith29's idea is a great possibility, but comes with risks.

Edited by liamfriel: n/a

0

Hi Guys,

Thank's for all your help so far.

Sure. I have 2 files pulling this together so far.

index.php

include('includes/global.php');
DisplayIndex();

global.php

function DisplayIndex() {

	ConnDB();

	$index = mysql_query("SELECT * FROM pages WHERE url='index' AND page_group='0'") 
	or die(mysql_error());

		while($pager = mysql_fetch_array( $index )) {

			
			include('build.php');
			include('_lang.php');
			include('seo.php');
			include('design/1.php');
				
				echo $pager['code'];

			include('design/2.php');

		}

}

As you can see, the content is stored in a mysql database.

What i would like is that when someone stores somthing like this in the database:

Contact Us
[enquiry]

Or browse view our gallery
[gallery]

They will appear from an includes. $pager is pulling the content for the page.

Zack.

Edited by Zack_G: n/a

0

Hmmm, am I missing something as I don't understand why you are doing it that way why not make your path then include it...

$path = "includes/" . $pager['code'] . "/index.php";
include( $path );

As an example.

As I said I might have missed something.

0

Hi,

Basically a client can login and update the content of there webpage. This content is saved to a mysql database.

Onto the next part, when the mysql database content is pulled and displayed on the actual webpage during a echo i need to be able to scan for tags, for example [enquiry] or [gallery] and include the relevent file for that tag.

Let's say the customer udpates the content of there index page to say "This is my index page. Why not email me using our contact form [enquiry]" then we need to include enquiry.php.

Currently everything works apart from the whole issue with searching and replacing tags with the relevent include file.

Zack.

0

This would be very annoying as you would need to stop outputting the database information, place the include(); and then start echoing out the rest.

I would have no idea where to start with something like that.

One idea would be to load both pages into a variable at the start names $enquiry and $gallery and output them that way.

Edited by liamfriel: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.