so in this video we're going to be um
generating the title for our links so
let's get
started so you'll see if we come back to
our code here the first thing we want to
do before we actually insert a link into
the database is we want we want to uh
generate the random string that is going
to be the link so what I'm going to do
is I'm going to paste in this function I
found in stack Overflow it's a function
that generates a random string um and we
don't want any numbers in our string so
we're just going to delete the numbers
at the beginning of it
so we want an alphabetical string to be
generated uh the length by default is 10
so uh we can live with that so we're
just going to use the Generate random
string function to generate our title so
the way we do that is we just come up
here and say generate title just um to
create a comment so we know what's going
on then we're going to say title equals
Generate random string and that's all we
have to do so what I'm going to do is
I'm going to Echo title and I'm going to
comment this out just temporarily so
that we can see it in action so let's
click yes upload the
file uh let's uh just click shorten link
you can see it generated a random string
of uh alphabetical characters if I click
it again you'll see we'll get a
different
string so we're going to use these for
our links so now that we have our title
generated we can uncomment this code and
we can just change this to um we can
actually just put title straight in here
because we're not actually taking the
title from the user so no user input is
um involved in this so we don't need to
worry about SQL inaction which is why we
can put the title uh variable in the
query but for consistency what we can do
is just put a question mark
there uh and we'll just put another s
here to say we want two strings and we
will put another comma here and we'll
put title in there so that just makes
things a bit more
consistent so let's um upload this and
just put in a link so say google.com
it says done and when you uh click
browse and you can see it says
google.com and it says title and we have
our uh random link generated and put in
the field so another thing we're going
to do uh if we go back to our links here
you'll see that they have uh no HTTP or
https in front of them so we're going to
put that in um if it's not already there
so the way we do that is we just come up
here and we'll say insert http
um we'll just actually insert HTTP
because if https is already there we
won't need to insert anything so we'll
say insert HTTP and what we're going to
do is we're going to say
if uh
post URL to shorten and we actually need
to put this in round brackets so we're
going to say if you actually
use so we're going to use the substr
function so we're going to say
substr uh and you'll see here HTTP is
four letters then it has a colon into
two um forward slashes so that's seven
characters in total so what we going
what we're going to put in here is uh 0
or 07 so this means we want to get the
first seven characters of uh whatever
the user puts in this text box and we
want to check it to see if uh that
equals uh HTTP col 4 for Slash and then
if it doesn't we're going to uh prean it
to the string so the way we check it is
we say equals
uh here CDP colum slash and then we'll
say actually we'll put a not equals in
we'll just put a comment here then
prepend HTTP column4
SL so the way we're going to do this
we're just going to use a variable
called URL and we'll set it equal to um
HTT
whoops HTTP col for
slash.
post uh whoops URL too
shorten and here we will just
say copy this and say
else URL equals um our post variable and
we're going to instead of putting it in
here we're just going to pass it the URL
variable so if we run this now we should
have HTTP appended on or prepended onto
the start of our string if we don't
already provide it one so I'm just going
to put in prism.com
and you can see that was changed to http
Francis
mn.com if I put in
HTTP
youtube.com what we should get is
exactly what I put in the text box so
you can see now it says HTTP
youtube.com so that's it for this video
don't forget to like comment favorite
And subscribe and I'll see you next time