Hello there, I'm really in trouble with this preg_replace and any kind of help is greatly appreciated. Here is what I want: I have box where people may reply topics, and whenever they write (See: xxx yyy zzz) I want that xxx yyy zzz to be a link, but not the "see:" part. So basically, every word between See: and " ) " will become a link. I hope I was clear enough. Thank you.
Try this: $string = preg_replace('/See: (xxx yyy zzz)/iUsm','<a href=$1>$1<\/a>',$string); PHP: not tested
here is my string; $string = '(see:aX maasdasd asdasd asdasaaa) see: xxx yyy zzz (SEE: HELLO WORD)over the lazy dog. see:asd.com'; using your code the part starting from xxx becomes all a link, not only xxx yyy zzz. For example in this string, I want that "aX maasdasd asdasd asdasaaa" and "HELLO WORD" to become link as they are written within paranthesises. I know, that's not an easy one but I think it's not impossible. Javascript will do too, I don't really care about the language. I just need the script
ThePHPMaster your ThePHPnoob not master,your code is not working and your code is not safe at all, even 3 years old kids will know how to bypass your code, and do XSS, but I know you dont know what is XSS, first learn security of php ,and then go here and give your code.. Shakon You need know what symbols urls can contain, then you write pattern what will accept only if url contains allowed symbols.. its easy..
well write me down a script if its easy. This is exactly what I want; (See: digitalpoint) ==becomes==> (See: digitalpoint) Please don't write me a script like preg_replace("/digitalpoint/", "< a href bla bla bla", $string). I don't want only digitalpoint to be link but whatever it comes there, if someone writes dictipedie I want (See: dictipedie) I hope I was clear enough.
I have no idea what the hell neegeris was saying... Anyway, here ya go: $string = '(see:aX maasdasd asdasd asdasaaa) see: xxx yyy zzz (SEE: HELLO WORD)over the lazy dog. see:asd.com'; preg_match_all("/\(see:(.*?)\)/i", $string, $matches); foreach ($matches[1] as $match){ echo "<a href=http://www.google.com>".$match."</a><br>"; } PHP:
how do i grab this with pregmatch s1.addVariable("file","http://aol.com/aoluser/aolvideos/4a614672/4a4dfa0a04ee6.flv"); Code (markup): any help ? i did try file= doesnt work any other idea?
goramba thank you mate. However, even though that's the closest one to my goal, your code strips other texts away which is something that I don't want at all. Thank you again for your concern.
I'm starting to think you're a troll. First, I just worked to solve his problem, not write a whole security class for him. If we get a working piece of code we can talk security. Second, you keep chiming in but with nothing to contribute - just working on your arrogant post count? Hmm... With the string you posted and your request it seems to do what you asked. Maybe if you post a real example and the exact output you want I can modify it.
I believe this is the clearest example I can make. (See: dictipedie) ==becomes==> (See: dictipedie) However, that's not only that. If someone would write (See: Dictipedie - Spread Your Knowledge!) the link will contain spaces which at the end will be encoded to %20, instead of this I want "_" in the < a > tag's href section instead of spaces. Here is what I exactly want. (See: Dictipedie - Spread Your Knowledge!) ==becomes==> [html version] See: <a href="topic.php?t=Dictipedie_-_Spread_Your_Knowledge!">Dictipedie - Spread Your Knowledge!</a> [output version] (See: Dictipedie - Spread Your Knowledge!) Well because I am not native and the problem is a bit complicated it's a bit hard to explain it properly, but I hope the example was clear enough. Thank you again for your concern.
Ok, simple change: $string = '(See: Dictipedie - Spread Your Knowledge!)'; preg_match_all("/\(see: (.*?)\)/i", $string, $matches); foreach ($matches[1] as $match){ $nospace=str_replace(" ", "_", $match); echo '(See: <a href="topic.php?t='.$nospace.'">'.$match.'</a>)'; } PHP: RESULT: (See: <a href="topic.php?t=Dictipedie_-_Spread_Your_Knowledge!">Dictipedie - Spread Your Knowledge!</a>)
Didn't have my server up at that time, now this is tested and working fine: <?php $string = 'sdfsdflk lkjsdf See: xxx yyy zzz ;kljs;dkf ;kjsdfoijoij234 See: xxx yyy zzz kjsdf;klj See: xxx yyy zzz'; $string = preg_replace('/See: (xxx yyy zzz)/U','<a href="$1">$1</a>',$string); echo $string; ?> PHP:
yeah thank you bro=) I'm so close now, just a minor problem, what if the string was $content = 'word word _anotherword _anotherword asda (see: me) (see: asdasd hheheh) (see: hehehe hihiih ha) ( see:asdasd) see: hehehe ( see : asd1231 1231 <>)'; I want the string to remain as it is and the (see: x) parts to change. lol I know I am bothering a lot but I really need this code =)