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 :)

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?

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 :/

Member Avatar for diafol

use preg_split() to array:

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

Your url will be the second item.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.