Jump to content


Photo

How to str_tags and str_replace in an array


  • Please log in to reply
2 replies to this topic

#1 freakus_maximus

freakus_maximus
  • Members
  • PipPipPip
  • Advanced Member
  • 177 posts

Posted 20 March 2006 - 08:21 PM

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.)

$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 );

Thanks for any help!

#2 micah1701

micah1701
  • Members
  • PipPipPip
  • Advanced Member
  • 613 posts
  • LocationEllington, CT USA

Posted 20 March 2006 - 08:37 PM

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)
}

"Confidence in the face of risk."

#3 freakus_maximus

freakus_maximus
  • Members
  • PipPipPip
  • Advanced Member
  • 177 posts

Posted 20 March 2006 - 08:45 PM

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!


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 );





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users