473,395 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

str_replace and include() together

Hi guys.

Here is my problem:

I have a php file which is associated by a number/ID.

together with BB Code my goal is to have the BB Code transfer the tags with the ID into an include of the file.

I don't think I can use file_get_contents because there is PHP scripts inside the file.

example: [file]2[/file]
= include("file_with_id_2");

But I have not found a way to do this.
Any tips? :)
May 8 '11 #1
3 2073
johny10151981
1,059 1GB
Do you know how to operate of string?
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $var_id=2;
  3. $var_file_name='file_with_id_'.$var;
  4. if(file_exists($var_file_name)==false)
  5. {
  6.  echo "Missing File";
  7.  exit;
  8. }
  9. include_once($var_file_name);
  10.  
  11. ?>
  12.  
May 9 '11 #2
dgreenhouse
250 Expert 100+
Just concatenate the id onto the base file name (I assume that's what you want).

i.e.
Expand|Select|Wrap|Line Numbers
  1. <?php // @file: variable_include.php
  2. for ($i=0; $i < 2; $i++)
  3. {
  4.   include("variable_includes$i.php");
  5. }
  6. ?>
  7.  
  8. <?php // @file: variable_include0.php
  9. echo 'Hello this is file: variable_includes0.php<br>';
  10. ?>
  11.  
  12.  
  13. <?php // @file: variable_include1.php
  14. echo 'Hello this is file: variable_includes0.php<br>';
  15. ?>
  16.  
  17. Output:
  18. Hello this is file: variable_includes0.php
  19. Hello this is file: variable_includes1.php
  20.  
May 9 '11 #3
Thanks for your reply. It might work, but what I was looking for is to replace a part of a larger text, into a file include.

I have a script that handles this 'BB Code' before it's made visible to the user, so it wouldn't work to include it right there.

example:
Expand|Select|Wrap|Line Numbers
  1. $content = str_replace("[file]2[/file]", include(file2.php), $content);
May 9 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Tom Cat | last post by:
Is there anything wrong with using a lot of include files? On one part of my website, I have a form. The page it posts data to, includes a different file based on some of the values. The...
14
by: Jon Rea | last post by:
I am currently cleaning up an application which was origainlly hashed together with speed of coding in mind and therefore contains quite a few "hacky" shortcuts. As part of this "revamping"...
9
by: chat | last post by:
Hi, every body. I have 3 files like this: -------------------------------------------------------- file name : header.h #ifndef TEST_H #define TEST_H int a=1; double b=0.5;
4
by: geshan | last post by:
In php5 I am not able to use include funciton and header("location:""" together please help.
2
by: key9 | last post by:
Hi all look at the organize tree main.c ------ #include lib_adapter.c main() { foo();
10
by: Joah Senegal | last post by:
Hello all, I';m getting fucking crazy out here. I want to kill people an all the computer around. Well to the point... I;m trying to do something very very simple (atleast it should be simple)...
4
by: Jon Slaughter | last post by:
I'm using eval to excute some mixed php and html code but I cannot debug it. I am essentially using filegetcontents to load up a php/html file and then inserting it into another php/html file and...
1
by: wish | last post by:
Hi, I will like to know how to i attach together with the query in the include.. eg. include "main.php";
4
by: MimiMi | last post by:
I'm trying to put together a http response header. It seems to work, except for that I don't get the data string added correctly! I wouldn't be surprised if my problems have something to do with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.