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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing HTML tags 1

Status
Not open for further replies.

mrblonde100

Technical User
Nov 22, 2009
5
GB
Hi all,
I hope you can help me; I’m very new to PHP but managed to pick up a fair bit over the past couple of weeks. Although I have come across a problem that I can’t seem to resolve.

I'm trying to extract some specific data from my MYSQL database using PHP, and then feed it into Flash. The Flash content then dynamically updates its text fields depending on the content of the MYSQL database.

It has taken me days to get this far and I’m finally there. Although a new problem has stumped me. The Flash is replicating the MYSQL perfectly, but including the HTML tags from within the record. These tags are being passed by the PHP.

I need the tags to remain within the original database record, as they format HTML content on other pages within the site, so removing them at source is not an option. The tags are the <p> and </p> content tags.
I’m trying to strip them out during the PHP process before the content is picked up by Flash.

I have tried strip_tags() but can’t seem to get it to work properly. Adding this function and running it on the QUERY string causes the echo function to break. I may have it in the wrong place.

I think I’m nearly there but just can’t figure it out.
I have pasted my code below, this code is working perfectly and assigning a variable to each of my extracted elements which is then assigned to Flash. The $intro variable/query is the variable that contains the tags.

The content that is being extracted is in this example format:
<p>Hello World, how are you today</p> is it possible to strip these tags out and pass Flash the rest?
Any advice of guidance would be gratefully received. I have researched this extensively and looked into the strip_tags function adding this function causing the $Intro write to fail.
Many thanks!
My PHP code is below:

<?php
$connect = mysql_connect("HOST", "USERNAME", "PASSWORD");
mysql_select_db("DATABASE");
$result = mysql_query("SELECT price, id, image1, state, locality, listdate FROM record WHERE state = 'alpha' AND featured = 1 ORDER BY listdate");
$intro = mysql_query("SELECT introtext FROM jos_content WHERE catid = 929 AND ordering = 2");
$cant = 0;
while($row=mysql_fetch_array($result)){
echo "locality$cant=$row[locality]&price$cant=$row[price]&propid$cant=$row[id]&image1$cant=$row[image1]&area$cant=$row[state]&";
$cant++;
}
while($row=mysql_fetch_array($intro)){
echo "introtext$cant=$row[introtext]&";
$cant++;
}
echo "cant=$cant";
?>




 
strip_tags is correct. pass the output of this function to your flash controller.
 
As jpadie points out, strip_tags is correct. Perhaps if you show us how you are using it we may be of more help.

Should something like this:
Code:
$output=strip_tags($texttostrip);



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks for coming back to me, i thought the striptag() might be the answer and i implemented it before. But i wasnt 100% sure on the syntax so thanks for clafifying it vacunita.

If i add this striptag() funtion to my code like this:

__________________
<?php
$connect = mysql_connect("HOST", "USERNAME", "PASSWORD");
mysql_select_db("DATABASE");
$result = mysql_query("SELECT price, id, image1, state, locality, listdate FROM record WHERE state = 'alpha' AND featured = 1 ORDER BY listdate");
$intro = mysql_query("SELECT introtext FROM jos_content WHERE catid = 929 AND ordering = 2");

$introstriped=strip_tags($tintro);

$cant = 0;
while($row=mysql_fetch_array($result)){
echo "locality$cant=$row[locality]&price$cant=$row[price]&propid$cant=$row[id]&image1$cant=$row[image1]&area$cant=$row[state]&";
$cant++;
}
while($row=mysql_fetch_array($introstriped)){
echo "introtext$cant=$row[introtext]&";
$cant++;
}
echo "cant=$cant";
?>

The will run the first echo, but when it gets to the echoing the introtext it fires back this message:

"Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/fhlinux136/n/norwegianproperty.net/user/htdocs/get/hedmark-props.php on line 22"

Line 22 is "while($row=mysql_fetch_array($introstriped)){"

Is the striptag() bit changing the query string so its no longer recognised?

Many thanks for your help.





 
You're stripping the tags in the resource holder, which only holds information on your data, not the data itself. You retrieve the actual data only inside the while loop. That is where you should strip the tags (I have intentionally done only one step per line to avoid too much confusion. You can also do everything in one echo line):
Code:
while($row=mysql_fetch_array($intro)){
    $introstripped = "introtext$cant=$row[introtext]&";
    $introstripped = strip_tags ($introstripped);
    echo $introstripped;
    $cant++;
}

[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Vragabond, thank you for your clear direction.

Your rejiggling of the code has fixed the PHP and the issue is resolved. I also learnt a new trick.

Thanks also to the other people who posted their thoughts.

Great community.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top