473,396 Members | 2,029 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,396 software developers and data experts.

Pulling variables from str_replace


Something simple, perhaps someone can shed some light.

I have an array of paragraphs of text and am replacing some of the text
using str_replace().

Ex.

function addGraphic($numGraphic){

return("this is graphic $numGraphic");

}

$instruction = str_replace("#GRAPHIC[$i]",addGraphic($i),$instruction);
Basically, I look for the tag #GRAPHIC[n] in the text where n is an
integer value and want to replace it with the text and the actual number
inside the brackets. I am unsure how to parse this value out and then pass
it to the function that will create the appropriate output.

Thanks for any help.
Sep 21 '06 #1
2 1580

Brad Everman wrote:
Something simple, perhaps someone can shed some light.

I have an array of paragraphs of text and am replacing some of the text
using str_replace().

Ex.

function addGraphic($numGraphic){

return("this is graphic $numGraphic");

}

$instruction = str_replace("#GRAPHIC[$i]",addGraphic($i),$instruction);
Basically, I look for the tag #GRAPHIC[n] in the text where n is an
integer value and want to replace it with the text and the actual number
inside the brackets. I am unsure how to parse this value out and then pass
it to the function that will create the appropriate output.

Thanks for any help.
Hey Brad,
You need preg_replace_callback(). str_replace() won't work with more
than one string unless you make a huge array for the search and replace
params.
-Blayde

Sep 21 '06 #2
In a contingent reality, Blayde possibly said:
>
Hey Brad,
You need preg_replace_callback(). str_replace() won't work with more
than one string unless you make a huge array for the search and replace
params.
-Blayde
Thanks, that worked perfectly.


Sep 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: LRW | last post by:
I have an automated process which uploads a comma separated spreadsheet (csv) and inserts it into a database: $sql = "LOAD DATA INFILE '".$uploadfile."' INTO TABLE `tbl_tracking` FIELDS...
12
by: frizzle | last post by:
Hi there, i've built a multi-langual site. Languages are defined by a variable in the url -> 'l=en'. There can be more variables in the url: mydomain.com/site.php?l=en&item=5&name=foo, but l=en...
1
by: marcomputers | last post by:
Hi, I'm trying to automatically update an existing rss podcast file using php and the str_replace function. Every time I add a media file, it should read the .rss file into a string, take the...
10
by: Alan Little | last post by:
class example { var $Stage; function example() { $this->Stage = 'init'; $x = ???????; echo $$x; }
9
by: Wayne | last post by:
$a = $_POST; # txt_content = This is a<CR><LF>Test $p = str_replace ("%0D%0A", "<br>", $a); That is the above code that I am using, however, it is not picking up the CR/LF from the textarea. I...
4
by: The Numerator | last post by:
I have this page (print.php). In that file, I want to to include a text file from "songs/breathe.txt", and replace all instances of "<b" with "<span" and "</b>" with "</span>". I know how I should...
5
by: magic_hat60622 | last post by:
hi all. I have an html file that I need php to read and send as an html e-mail. The file contains standard html and also some variable names that I want php to interpolate: <html> Hi there. my...
7
by: abscons | last post by:
Hi out there, I have an url that looks like this: http://host/file?var=value. I am trying to replace the "value" part in my url and assign it to a link on my page. I tried to parse the url but can...
5
by: jmark | last post by:
I saw this example in php.net // Outputs: apearpearle pear $letters = array('a', 'p'); $fruit = array('apple', 'pear'); $text = 'a p'; $output = str_replace($letters, $fruit, $text);...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.