Jump to content


This topic is now archived and is closed to further replies.


How to str_tags and str_replace in an array

Recommended Posts

Before anyone says I shouldn't allow tags in the initial form, I know. In this situation the application is internal (not on the 'net) and the user base limited. I am using a java app ("TinyMCE") to allow users to enter text and apply some limited formatting. The app stores the tags in the db along with the text. Such as:

<strong>Here is some text</strong>

I need to maintain this so I can present it back to the user in the same format. So, please no bashing about that.

The problem I am having is actually with the following code. This grabs the data from the db and dumps it out to an Excel spreadsheet. This works, no problem there.

But, I need to str_tags the "description" column in this example to remove the tags. Can't seem to figure out how to do that with the array. Any help? (I mentioned the str_replace as well in my Topic Title and hoping the solution to the first problem gives me direction on the this as well.)

[code]$headers = ("FancyNameColumn1"."\t"."FancyNameColumn2"."\t"."FancyNameColumn3."\t");

$result = mysql_query('select defectnum, description, username from release_notes_tbl');
$count = mysql_num_fields($result);

$data = array();
while($row = mysql_fetch_row($result)) {
array_push($data, $row);

$xls_rows = '';
foreach( $data as $row )
$xls_rows .= xls_format_row( $row );

xls_send( $headers, $xls_rows );[/code]

Thanks for any help!

Share this post

Link to post
Share on other sites
what if you strip it before you add it to the array:

while($row = strip_tags(mysql_fetch_row($result))) {

would that do it? (i didn't test it, just suggesting)

if that doesn't work

get your row count first, strip the tags, then use a for loop to build the array. something like:

$rows = mysql_num_rows($results);
$row = mysql_fetch_row($results);

for($i=0; $i<$rows; $i++)
$value = strip_tags($row[column]);
array_push($value, $i)

Share this post

Link to post
Share on other sites

It was easier than I thought.

I just added the two right before the xls_send since the data was being sent as one string.

Thanks for the quick reply!

[code]foreach( $data as $row )
$xls_rows .= xls_format_row( $row );

$xls_rows = str_replace(array("</p><p>", "</li><li>"), ", ", $xls_rows);
$xls_rows = strip_tags($xls_rows);

xls_send( $headers, $xls_rows );[/code]

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.