Jump to content

How to str_tags and str_replace in an array


freakus_maximus

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!
Link to comment
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)
}
Link to comment
Share on other sites

Hehe...oops!

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.