0

Hi :)

I have a page where users can enter youtube url's within bbtags such as:

[Youtube ]youtube-url-here[ /youtube]

However...I'm having some problems when the url contains the &amp sign..as this seems to cut off the string at this point.

I've read somewhere that one have to use urlencode these signs..but I'm not completely sure how to do this without loosing any security in case the user inserts some other urls / code which I don't want here..
So hopefully one of you wizards may help me out somewhat along the way ? :)

The youtube url is part of a long text (it's a comment system ) - If the user inserts it of course... so We always have to check if the user actually inserted a youtube link or not before doing whatever functions we need to do with the string contents afterwards.

Very happy for any help you guys may provide :)

Edited by Aksel: typ

4
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by vibhaJ
0

When your form is submitted use urlencode in following way before inserting into database.

$comment = urlencode($_POST['comment']);

I think it should not cutoff with &amp, What is field type of comment in database?

0

When your form is submitted use urlencode in following way before inserting into database.

$comment = urlencode($_POST['comment']);

I think it should not cutoff with &amp, What is field type of comment in database?

Hi :)

Thanks for the quick reply.

But do you have any advice on how I could JUST urlencode the string with the youtubeurl in it and not anything else? (it's a comment field so it got quite alot of text in it) .

The commentfieldtype is a 'text' fieldtype btw :)

The url should always start with [youtube ] and end with [ /youtube] (without the spaces )

I've tried using preg_match..but I must admit I'm rather new to regexp so I'm having some trouble unfortunately :/

0

use preg_split() to array:

1) TEXT + [youtube ]
2) URL
3) [ /youtube] + TEXT

Your url will be the second item.

Edited by diafol: n/a

0

as per ardav:

$text = "this is description...this is description...this is descr[youtubeee]http://www.youtube1...[/youtubeee]iption...this is description...this is description...[youtubeee]http://www.youtube-two...[/youtubeee]this is description...this is description...this is description...this is description...this is description...this is description...";
preg_match_all ("/\[youtubeee\]([^`]*?)\[\/youtubeee\]/", $text, $output,PREG_OFFSET_CAPTURE);	
echo '<pre>';
print_r($output);

in array you will have offset, once you done with urlencode replace main string back using offset.

Edited by vibhaJ: when i use &quot;youtube&quot; post converted to some embeded tags.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.