473,324 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Removing html anchors from POST'ed text string

I am having problems with trying to remove some tags using PHP. What I
want is to perform a search and replace on a URL, so if someone tried to
put a URL into a guestbook database, instead of the user inputting a
link as:

<a href="http://whatever.com">visit me</A>

It goes into the database as:

http://whatever.com

I have tried the str_replace() function, but doesn't seem to work. I have
also tried strip_tags() but then that just give the result:

visit me

This is the code I've written.

$AmendedComment = str_replace("<a href=\"", " ", $_POST['Comment']);
$FinalComment = addslashes($AmendedComment);

Checking the database and reading it out again, the first part of the URL
remains intact, so the URL is clickable - not what I want.

I've made an attempt at preg_replace() but it's difficult to get head
around trying to write a pattern.

Any help appreciated.

Dariusz
Jul 17 '05 #1
1 1713
In article <Ri*********************@stones.force9.net>,
ng@lycaus.plusYOURSHIT.com (Dariusz) wrote:
I am having problems with trying to remove some tags using PHP. What I
want is to perform a search and replace on a URL, so if someone tried to
put a URL into a guestbook database, instead of the user inputting a
link as:

<a href="http://whatever.com">visit me</A>

It goes into the database as:

http://whatever.com
[...]
I've made an attempt at preg_replace() but it's difficult to get head
around trying to write a pattern.

First attempt (I checked that it works on your example, I didn't try
anything else):

$href = '<a href="http://whatever.com">visit me</A>';
$unclickable_url = preg_replace('!<a.+?href="([^"]+)".*?</a>!i', "$1",
$href);
echo $unclickable_url;

I'm sure this is not good enough yet. Feel free to improve, anyone.

JP

--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Busy | last post by:
Hello Folks Does anybody know why the text box on this page is trunctating $test to Mary? Thanks Nick <html>
2
by: johkar | last post by:
Would there ever be any problems with the following script depending on what type of characters are in the text string? I am appending the value of hidden form field to the query string. ...
4
by: Nedo | last post by:
hi is there a simple way to convert a html-string to a plain text-string? thanks Nedo
2
by: charlie_M | last post by:
I have the following code: <script type=text/javascript> function hide_tooltip(){ var hp = document.getElementById("tooltipper"); hp.style.left=0; hp.style.top=0; hp.style.width=1;...
8
by: McBeth | last post by:
Hi! I'm trying to call external HTML web page requiring several POST-ed parameters from C# Web form. Parameters should be set by Web form. Is it possible ? How can I do it ? Thanks in advance ...
2
by: dangonzale | last post by:
I cannot use anchors on this page so I was wondering first of all if its possible and second if there are scripts out there that do this. I'd like javascript to find a text string on another page...
5
by: menriquez | last post by:
Hi...I am trying to write a test html/php app that accepts some POSTed XML data and replies with (for now) an echo of the $_POST array. Here is my index.htm.. <!DOCTYPE html PUBLIC "-//W3C//DTD...
4
by: Ahmed, Shakir | last post by:
I need to remove text string from the list of the numbers mentioned below: 080829-7_A 070529-5_c 080824-7_O 070405_6_p The output will be : 080829-7 070529-5
0
by: Adam Pletcher | last post by:
You just want to drop the last two characters? Slice it. 080829-7 - Adam Behalf
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.