sean14592 Posted June 4, 2008 Share Posted June 4, 2008 Hi, I need to check a text box if it contains the <a> tag. Any ideas? Sean Quote Link to comment Share on other sites More sharing options...
kbh43dz_u Posted June 4, 2008 Share Posted June 4, 2008 you probably want to use strip_tags($text, '<p><div>'); and strip all except allowed tags. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 4, 2008 Share Posted June 4, 2008 if you are searching for that, and then acting on just <a> and nothing else: <?php $textarea = $_POST['text']; //change this if needed if (strstr($textarea, "<a>")){ //do what you're going to do } ?> Quote Link to comment Share on other sites More sharing options...
discomatt Posted June 4, 2008 Share Posted June 4, 2008 if ( strpos( $_POST['textboxName'], '<a' ) !== FALSE ) echo 'Found an <a> tag!'; Quote Link to comment Share on other sites More sharing options...
sean14592 Posted June 4, 2008 Author Share Posted June 4, 2008 I have tried... if ((strstr($main_desc, "<a")) || (strstr($area_desc, "<a")) || (strstr($getthere_desc, "<a"))){ echo '<br><center>'; echo 'Opps! Looks like we have a problem....<br><br>'; echo '<b>Error: <FONT COLOR="#FF3300"><u>You cannot include links in your any part of your listing unless specifically asked!</u></b></font>'; echo '<br><br><a href="'.$siteurl.'index.php?p=oaddprop5"><img src="'.$siteurl.'style/form/fix_error.gif" width="240" height="40" border="0" /></a>'; exit; } ...sadly didnt work, i used <a> and didn't get any error, I will try other now I have also tried... if ( strpos( $_POST['main_desc'], '<a' ) !== FALSE ){ echo 'Found an <a> tag!'; } ...still dosent work Sean Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 4, 2008 Share Posted June 4, 2008 worked for me: <?php $test = "this is a <a href='test'>test</a>"; if (strstr($test, "<a")){ print "I found you!"; } ?> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 4, 2008 Share Posted June 4, 2008 If those don't work for you, you can try: $post = "Lololol <a href=\"lol.php\">O_O</a>"; if (eregi('<a(.*)>', $post)) { echo "Here!\n"; //stuff } else { echo "Nope\n"; //other stuff } Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 4, 2008 Share Posted June 4, 2008 If you're a PCRE kind of person, here: <?php $post = "Lolol <a href=lol.php>O_O</a>"; $reg = '/<a(.*?)>/'; if (preg_match($reg, $post)) { echo "Win!"; } else { echo "Fail!"; } echo "\n"; ?> Either works. Quote Link to comment Share on other sites More sharing options...
sean14592 Posted June 4, 2008 Author Share Posted June 4, 2008 If those don't work for you, you can try: $post = "Lololol <a href=\"lol.php\">O_O</a>"; if (eregi('<a(.*)>', $post)) { echo "Here!\n"; //stuff } else { echo "Nope\n"; //other stuff } Ok, when i try this i get.... Warning: eregi() [function.eregi]: REG_BADRPT in ******/public_html/pages/oaddprop6.php on line 154 Nope line 154 is.... if (eregi('<a(.*)>', $post)) { Cheers Sean Quote Link to comment Share on other sites More sharing options...
sean14592 Posted June 4, 2008 Author Share Posted June 4, 2008 If you're a PCRE kind of person, here: <?php $post = "Lolol <a href=lol.php>O_O</a>"; $reg = '/<a(.*?)>/'; if (preg_match($reg, $post)) { echo "Win!"; } else { echo "Fail!"; } echo "\n"; ?> Either works. I get fail every time Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 4, 2008 Share Posted June 4, 2008 Let me see what's actually in your variable. Because it works for me. Please show us the output of echo $_POST['whatever'] (I don't know which key you're using, lol), and obviously put in the correct key. (And you're making me use PHP 5 for this. =( PHP6 doesn't use ereg anymore. That's why I wrote a PCRE one too, lol.) Quote Link to comment Share on other sites More sharing options...
sean14592 Posted June 4, 2008 Author Share Posted June 4, 2008 Here is my full code: Form http://pastebin.com/m6e3ba10d Process Page http://pastebin.com/m22ec71e Cheers Sean Quote Link to comment Share on other sites More sharing options...
sean14592 Posted June 4, 2008 Author Share Posted June 4, 2008 I'm using PHP 5 Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 4, 2008 Share Posted June 4, 2008 Please show me an example of what would in $main_desc or whatever. Quote Link to comment Share on other sites More sharing options...
sean14592 Posted June 4, 2008 Author Share Posted June 4, 2008 In $main_desc I enter '<a' and I get fail(false), good but if I enter 'sdsadas' I get Fail Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 4, 2008 Share Posted June 4, 2008 Enter: <a> That's an <a> tag. Rofl. =/ *Sighs* Quote Link to comment Share on other sites More sharing options...
sean14592 Posted June 4, 2008 Author Share Posted June 4, 2008 lol, my question was to stop <a, but same thing. I enteed and get back 'Fail!' Sean, btw thanks for helping Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 4, 2008 Share Posted June 4, 2008 That's impossible... I just entered this script: <?php $post = "<a>"; if (eregi('<a(.*)>', $post)) { echo "Lol\n"; } ?> And it output "Lol". It should work if you're doing it correctly. Quote Link to comment Share on other sites More sharing options...
sean14592 Posted June 4, 2008 Author Share Posted June 4, 2008 ok, I tried that script like before, I works if i enter <a>, it displays "lol" Though it also displays "lol" if I enter "dsdasdas" weird sean Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 4, 2008 Share Posted June 4, 2008 Doesn't for me. I just tried it. Quote Link to comment Share on other sites More sharing options...
sean14592 Posted June 4, 2008 Author Share Posted June 4, 2008 have u got msn, so i can let u try on my site? cheers sean Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 4, 2008 Share Posted June 4, 2008 SerpentScars@hotmail.com Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.