str_replace help needed

Reply

Join Date: Sep 2009
Posts: 9
Reputation: Zack_G is an unknown quantity at this point 
Solved Threads: 0
Zack_G Zack_G is offline Offline
Newbie Poster

str_replace help needed

 
0
  #1
29 Days Ago
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 24
Reputation: liamfriel is an unknown quantity at this point 
Solved Threads: 1
liamfriel's Avatar
liamfriel liamfriel is offline Offline
Newbie Poster
 
0
  #2
29 Days Ago
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.
They throw us away like yesterdays jam - Maurice Mossley

Please - rep if someone helps you, it can't be traded for stuff, but it's nice.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 9
Reputation: Zack_G is an unknown quantity at this point 
Solved Threads: 0
Zack_G Zack_G is offline Offline
Newbie Poster
 
0
  #3
29 Days Ago
What command would i need to replace with php code?

Kind regards,
Zack.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 523
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 61
network18 network18 is offline Offline
Posting Pro
 
0
  #4
29 Days Ago
  1. $str1 = array('[gallery]','[enquiry]');
  2. $str2 = "include('modules/gallery/index.php');";
  3. 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
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 9
Reputation: Zack_G is an unknown quantity at this point 
Solved Threads: 0
Zack_G Zack_G is offline Offline
Newbie Poster
 
0
  #5
29 Days Ago
Hi,

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

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

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

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

Zack
Last edited by Zack_G; 29 Days Ago at 7:31 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 15
Reputation: alagirinetaxis is an unknown quantity at this point 
Solved Threads: 3
alagirinetaxis alagirinetaxis is offline Offline
Newbie Poster
 
0
  #6
29 Days Ago
  1. <?php
  2.  
  3. $file_path = "gallery/index.php";
  4.  
  5. /* First Include Gallery Module */
  6.  
  7. include ($file_path);
  8.  
  9. /* Replace Gallery Module to Enquiry Module */
  10.  
  11. $file_path = str_replace("gallery","enquiry",$file_path);
  12.  
  13. /* First Include Gallery Module */
  14.  
  15. include ($file_path);
  16.  
  17.  
  18. ?>
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 15
Reputation: alagirinetaxis is an unknown quantity at this point 
Solved Threads: 3
alagirinetaxis alagirinetaxis is offline Offline
Newbie Poster
 
0
  #7
29 Days Ago
  1. <?php
  2.  
  3. $file_path = "gallery/index.php";
  4.  
  5. /* First Include Gallery Module */
  6.  
  7. include ($file_path);
  8.  
  9. /* Replace Gallery Module to Enquiry Module */
  10.  
  11. $file_path = str_replace("gallery","enquiry",$file_path);
  12.  
  13. /* First Include Gallery Module */
  14.  
  15. include ($file_path);
  16.  
  17.  
  18. ?>
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 9
Reputation: Zack_G is an unknown quantity at this point 
Solved Threads: 0
Zack_G Zack_G is offline Offline
Newbie Poster
 
0
  #8
29 Days Ago
Hiya,

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

Thanks
Zack
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 523
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 61
network18 network18 is offline Offline
Posting Pro
 
0
  #9
29 Days Ago
go ahead with your code, it should work, similar as mine
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 9
Reputation: Zack_G is an unknown quantity at this point 
Solved Threads: 0
Zack_G Zack_G is offline Offline
Newbie Poster
 
0
  #10
29 Days Ago
Hi Network18,

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

Zack
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC