Current location: Hot Scripts Forums » Programming Languages » PHP » parsing or slicing charactors from a table?


parsing or slicing charactors from a table?

Reply
  #1 (permalink)  
Old 07-07-05, 08:06 PM
0o0o0 0o0o0 is offline
Wannabe Coder
 
Join Date: Jul 2005
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
parsing or slicing charactors from a table?

K this may be hard to explain maybe not.

Say you have in your table a column for Numbers...

column with numbers
1000123
1000234
1000345
1001011

say you need to make a link out of only the last three numbers on each?

like Http://www.bogussite.com/photos/123/1000123.jpg

I got this far... Http://www.bogussite.com/photos/$number/$number.jpg

and it comes up... Http://www.bogussite.com/photos/1000123/1000123.jpg

I need to exclude the first four digits on this link... how do I do it..
so it'll pick up as..

Http://www.bogussite.com/photos/123/1000123.jpg

thanks again if ya can help!
Reply With Quote
  #2 (permalink)  
Old 07-07-05, 08:12 PM
0o0o0 0o0o0 is offline
Wannabe Coder
 
Join Date: Jul 2005
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
oops

theres more...

each number has a product code in front of it..

example..

YZR1000102
HDA1000123
SUZ1000232
KAW1000432

Motorcycle photos is what im trying to pull up.. using an existing OLD filing system of bikes, rather would figure this way out than redo the entire photo files and jpgs.

so dumping off.. KAW1000432 KAW1000 leaving me with ../432/1000432.jpg

thanks for any help...
Reply With Quote
  #3 (permalink)  
Old 07-07-05, 08:12 PM
jordie jordie is offline
Wannabe Coder
 
Join Date: Jun 2005
Posts: 179
Thanks: 0
Thanked 0 Times in 0 Posts
If you just want the last 3 charcters from the string use:
PHP Code:

$newNum substr($number, -13); 

Or if you need it to just kill the first 4 numbers use:
PHP Code:

$newNum substr($number4); 

These will both give you the same result at the moment, however if you extend the numbers then the second code will return the last 4 characters. Do you understand me?
__________________
Jordie Bodlay
php, mysql, postgres
css, xhtml
graphics, design
email me: jb2386@hotmail.com for any programming needs.
Reply With Quote
  #4 (permalink)  
Old 07-07-05, 09:31 PM
0o0o0 0o0o0 is offline
Wannabe Coder
 
Join Date: Jul 2005
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
thanks..

thats wicked and the speedy reply!!!...

gotta problem tho.. I use the $number elsewhere in the page.

So how would I go about ONLY using your example for the hyperlink

with out effecting $number where its used elsewhere in the product details of the page?


example..
Description:
YZR1000123 Yamaha 1999 exhaust intake..

"see photo" <--- link which is www.bogussite.com/photos/123/1000123.jpg

it effects the description part where YZR1000123 is also shown in the detail info.

Thanks again.
Reply With Quote
  #5 (permalink)  
Old 07-07-05, 09:37 PM
0o0o0 0o0o0 is offline
Wannabe Coder
 
Join Date: Jul 2005
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
or..

Hey is $newnum the new item youve sent me??

then another Identical script using $newnum2

for the second part of the hyperlink?

so.. http://www.bogussite.com/photos/$newnum/$newnumber2.jpg

ya? no? ya do? ya dont? ya do? I should buy a boat!!!! ya dont? ya do?


(sorry saw it in a movie somewhere)
Reply With Quote
  #6 (permalink)  
Old 07-07-05, 10:02 PM
0o0o0 0o0o0 is offline
Wannabe Coder
 
Join Date: Jul 2005
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks!

Yep exactly as you wrote it! Works great!

I think ive been exceptionally lucky on this board, I type a question, get an answer, and problem solved!

Thanks for your reply.
Reply With Quote
  #7 (permalink)  
Old 07-08-05, 03:28 AM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

echo "http://www.bogussite.com/photos/".substr($number, -13)."/".$number.".jpg"
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #8 (permalink)  
Old 07-08-05, 08:29 PM
0o0o0 0o0o0 is offline
Wannabe Coder
 
Join Date: Jul 2005
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
hey

That way works too! thanks guys.
Reply With Quote
  #9 (permalink)  
Old 07-08-05, 08:45 PM
0o0o0 0o0o0 is offline
Wannabe Coder
 
Join Date: Jul 2005
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
uh oh

spoke to soon...

using ..".substr($number, -1, 3)."/$number.jpg

comes out like this in a link...

../3/1000125.jpg

for some reason it just prints the number 3.

instead of the last 3 numbers 125.

Any ideas?

-----
Im sure alot of people will find this thread useful as well!
Reply With Quote
  #10 (permalink)  
Old 07-08-05, 08:55 PM
0o0o0 0o0o0 is offline
Wannabe Coder
 
Join Date: Jul 2005
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
furthermore

Dunno with my setup...

I fixed by just completely taking out the ,3

and changing the -1 to -3


exampled...
..".substr($number, -1, 3)."/$number.jpg

my fix

..".substr($number, -3)."/$number.jpg

Let me know if theres anything unsafe about this.. or potential error down the road.

Thanks!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Auto Dealer Script nuzzle PHP 17 04-14-10 08:34 PM
Advice parsing a html table to xml RossC0 JavaScript 3 03-22-05 02:10 PM
Problem with a sort table js function tdubyou JavaScript 0 05-03-04 09:19 AM
auto table resize derick_2k JavaScript 4 04-26-04 02:32 PM
Newbie MySQL fccolon PHP 2 03-16-04 10:54 AM


All times are GMT -5. The time now is 06:54 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.