Page 1 of 2
Strip from 15th character to the end
Posted: Tue Jul 14, 2009 9:44 pm
by azylka
Hi! I've got a really quick question. I need to strip a string, $url from the 15th character to the end. Can anyone help me?
Cheers,
Alex
Re: Strip from 15th character to the end
Posted: Tue Jul 14, 2009 10:00 pm
by Christopher
Re: Strip from 15th character to the end
Posted: Tue Jul 14, 2009 10:21 pm
by azylka
Thanks for the reference, but could someone actually write a snippet for me? I'm trying to find a quick solution, but the things I've tried don't seem to work. Don't ask why I'm not posting the code. I can't explain what it does in a readable paragraph. I'm just looking for a way to strip the last 15 characters off of a variable.
Cheers,
Alex
Re: Strip from 15th character to the end
Posted: Tue Jul 14, 2009 10:35 pm
by JAB Creations
Pay me $5 on Paypal and I'll be more then happy to write a snippet for you.
Re: Strip from 15th character to the end
Posted: Tue Jul 14, 2009 10:49 pm
by azylka
Lemme think... No. I need this within 12 hours. It's no laughing matter.
Re: Strip from 15th character to the end
Posted: Tue Jul 14, 2009 10:53 pm
by Christopher
JAB Creations wrote:Pay me $5 on Paypal and I'll be more then happy to write a snippet for you.
That's not appropriate except in the Business area of the site JAB ... and a little cruel ...
azylka, did you click on the link I posted. There are many code examples there. I am sure you can find one that truncates strings and pass a length of 15 to it.
Re: Strip from 15th character to the end
Posted: Tue Jul 14, 2009 11:00 pm
by azylka
I looked and tried 4 examples. I don't have them, and I have a deadline to meet. I just need a snippet. I used to have this code exactly, but of course, I reinstalled Windows and lost it.
Re: Strip from 15th character to the end
Posted: Tue Jul 14, 2009 11:03 pm
by Skara
The very first two examples show exactly what you need.
To quote something that gets said often enough... If you don't make any effort, why should anyone here?
Re: Strip from 15th character to the end
Posted: Tue Jul 14, 2009 11:21 pm
by azylka
I did make an effort. This is just so hard to explain. I'll try again.
Just check out
http://www.zylka.us/alias.html to see what I need done.
Re: Strip from 15th character to the end
Posted: Wed Jul 15, 2009 12:59 am
by Christopher
The substr() function take a string, a start position and a length. You have a string I assume. You want it to be cut down to a length of 15 characters. And you want it to start at the first character -- which in strings and arrays is 0.
Re: Strip from 15th character to the end
Posted: Wed Jul 15, 2009 1:31 am
by prometheuzz
azylka wrote:I did make an effort. ...
You didn't show that you did. The very least you could do is post what you have tried (using code tags!) and explain what error message(s) you received. Now it looks like (with an emphasis on "looks") you're simply waiting to be spoon-fed.
Re: Strip from 15th character to the end
Posted: Wed Jul 15, 2009 9:35 am
by azylka
I'll try to explain this again and give you a link.
So, I'm creating Alias, a service like bit.ly and all that. The first page requires you to input your name and a URL to shorten. Then, using the GET method the name and URL are transferred to a page that creates a random#.html ($url_created). The new page says:
Thank you for using Alias, $name.
Please give this link out: $url_created
The only problem is that the $url_created includes your name
and URL of the page that was created. I just want the $url_created to only include the name of the new page. I figured out that the name of the new page with .html is always 15 characters long, and the $name=name part comes after that. I want to be able to keep the first 15 characters, and strip the rest.
See how complicated it is? See what I mean at:
http://www.zylka.us/alias.html. I'll post code later if you still can't understand this.
Re: Strip from 15th character to the end
Posted: Wed Jul 15, 2009 9:54 am
by pickle
We all understand what you're trying to do. We also understand that this is something extremely simple to do if you'd just take the time to look at the examples. I think what you don't understand is at this point, none of us are going to give you one-liner piece of code because it doesn't appear that you're trying to solve the problem yourself. An underlying philosophy on these boards is that we help those that help themselves. A sure-fire way to get no help is to ask someone to do your work for you.
On the plus side, it would seem we all have faith that you can do this yourself.
Re: Strip from 15th character to the end
Posted: Wed Jul 15, 2009 10:27 am
by azylka
Here's what I've tried.
$end = substr("$url", -15);
and
$end = substr('$url', 0, 15);
Re: Strip from 15th character to the end
Posted: Wed Jul 15, 2009 10:34 am
by pickle
You don't need to quote $url. In fact, if it's wrapped in single quotes, you'll be working on the literal string '$url'.
You want everything after the 15th character. Your first line would have given you the last 15 characters, and your second (assuming you hadn't quoted $url) would have given you characters 0 - 14. You want to start at character 15 & not specify the length. Look at the first line in example 3.