473,322 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Select text at intervals for array

35
Okay, so this might be impossible to do. I want to select certain text in a database field using PHP, at certain intervals, such as once every 8 characters, select for 10 and put in array, skip the next 5 characters, select for 6 etc. This might sound odd but I want to select certain text from a large field that will be repeating itself at these intervals. Something like this:

I won't select this, but I will select this, and then not this, but will this.
And it will repeat itself. I am not the best with PHP so I'm not sure if this can be done. But each selection would be put into an array, so I can pull the parts out. Maybe I'm thinking of this the wrong way? If there isn't a way to do this, looks like there will be a lot of copy/paste into many fields instead of just once.

Thanks!
Jan 21 '08 #1
2 1493
Atli
5,058 Expert 4TB
Hi.

This is indeed possible. Everything is possible! :)

All you would have to do is set up a loop, which would increment an integer by some number each loop and grab an x amount of chars, starting from that integer.

Like:
Expand|Select|Wrap|Line Numbers
  1. # Set strings
  2. $inputString = "Some text to split into pieces";
  3. $outputString "";
  4.  
  5. # Set preset values
  6. $startIndex = 0;
  7. $skipAmount = 5;
  8. $readAmount = 5;
  9.  
  10. # Read parts of the input string into the output string
  11. $inputLength = strlen($inputString);
  12. while($startIndex < $inputLength) {
  13.   $startIndex += $skipAmount;
  14.   $outputString .= substr($inputString, $startIndex, $readAmount);
  15.   $startIndex += $readAmount;
  16. }
  17.  
You could replace the output string with an array and change the values but you get the idea.
Jan 21 '08 #2
d3vkit
35
Hi.

This is indeed possible. Everything is possible! :)

All you would have to do is set up a loop, which would increment an integer by some number each loop and grab an x amount of chars, starting from that integer.

Like:
Expand|Select|Wrap|Line Numbers
  1. # Set strings
  2. $inputString = "Some text to split into pieces";
  3. $outputString "";
  4.  
  5. # Set preset values
  6. $startIndex = 0;
  7. $skipAmount = 5;
  8. $readAmount = 5;
  9.  
  10. # Read parts of the input string into the output string
  11. $inputLength = strlen($inputString);
  12. while($startIndex < $inputLength) {
  13.   $startIndex += $skipAmount;
  14.   $outputString .= substr($inputString, $startIndex, $readAmount);
  15.   $startIndex += $readAmount;
  16. }
  17.  
You could replace the output string with an array and change the values but you get the idea.
Ah, that makes pretty good sense. I've got a new project now but I'll have to check this out later when I get a chance. It's actually quite easy isn't it :P Well thanks for your time, you've been very helpful.
Feb 6 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: point | last post by:
Hello there... I'm a PHP programmer and starting to learn JS... I have a following problem.... I have 3 select boxes! one is hotel one is destination and one is country... if someone...
1
by: Marco Alting | last post by:
Can anyone tell me how to write a routine that uses time-intervals, I would like to dynamically create an array of times like this: 9:00 9:30 10:00 10:30 This has an interval of half an...
3
by: Stewart | last post by:
Dear comp.lang.javascript, I have more than once wanted to manipulate the contents of select boxes dynamically, whilst the boxes contain <optgroup> tags. Manipulation of a select box containing...
2
by: BrianP | last post by:
Hi, I have had to invent a work-around to get past what looks like a JavaScript bug, the malfunctioning Perl-like JavaScript array functions including SPLICE() and UNSHIFT(). I have boiled it...
5
by: Dionysus | last post by:
Using (or massacring) PHP, I'm trying to read the contents of a text field in a database (magazine article) and then break it into lines and insert an image file ever 3-4 lines if the image is...
21
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays...
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
25
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if my question needs to be here or in coldfusion. If i have my question is in the wrong section i am sorry in advance an will move it to the correct section. ...
4
tjc0ol
by: tjc0ol | last post by:
Hi guys, I'm a newbie in php and I got error in my index.php which is: 1054 - Unknown column 'p.products_id' in 'on clause' select p.products_image, pd.products_name, p.products_id,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.