Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic web page - character replace help

Status
Not open for further replies.

Recordsetclown

Technical User
Jul 12, 2002
64
0
0
US
Hi,

I'm new to php programming and am looking for ideas. I am working with a program that generates web pages from database information using templated forms. Some of the database fields contain options that are formatted as a bulleted list in certain areas of the page, but as pipe separated options in other areas. I would like to display those pipes as commas.

Since the page is generated on the fly, I wonder if there is any way to have php look at either an individual field or the page as a whole after it is rendered and replace any pipes that appear.

Thanks for any direction you can provide.
 
The answer is yes. Or at least probably.
But it is unlikely that the formatted text itself is tired in the database so you would be better off finding the point at which the formatting is applied and changing your code there.
Failing that you should turn on output buffering and apply an auto append script that will parse your output (by examining the buffer) and change the necessary HTML

otherwise you may be able to achieve the same goal by using CDs (depending on the mark up) and could definitely do do using JavaScript.
 
The information is stored in the db as a pipe-separated text field. The program formats it to a bullet list, which is fine for the area it is intended for. If I put that field on another page, it gets no formatting. There are several such fields. The output buffer sounds promising since I don't want to see pipes anywhere. How would this be done?
 
again: your best bet is to handle the formatting at the point that the data is extracted from the database or processed for output.
it is not a good solution to parse the entire page for such data and to rewrite on the fly.
but if you must you would do something like the following:

Code:
auto_prepend_file = path/to/myStart.php
Code:
ob_start('myRewriteFunction');
function myRewriteFunction($string){
   //insert code to rewrite the pipes to ul's here
}

of course, in order to make this work you will need to have a way of accurately describing (probably via a regex) the data you wish to transform. For example if the data looked like this

Code:
~field|field|field|field~
then there would be no problem. i.e. there must be a way of determining the start and end of the sequence as well as each dividing point.

I repeat: this is NOT the way to achieve your goal. take the time to go through your code and change the output formatting.
or change the formatting in the database itself.

Code:
update tablename set fieldname='<ul><li>' & replace(fieldname, '|','</li><li>' * '</li></ul>'

although even this I would counsel against: databases should not IMO hold formatted data. that is the job of the viewer layer of your application
 
Thanks very much for your help. That gives me some ideas to consider.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top