472,956 Members | 2,614 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to split a string by number of chars ?

This has been done before but not sure how:

Say I have a string of 1000 chars. I want to split the string into two
variables (two array element variables would be OK) one has 200 chars
the other has 800 chars. How would I do this? Must be simple in PHP...
Jul 17 '05 #1
3 3222
On Sun, 07 Nov 2004 19:39:28 GMT, leegold2 <le*****@nospam.net> wrote:
This has been done before but not sure how:

Say I have a string of 1000 chars. I want to split the string into two
variables (two array element variables would be OK) one has 200 chars
the other has 800 chars. How would I do this? Must be simple in PHP...


substr

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2
Andy Hassall wrote:
On Sun, 07 Nov 2004 19:39:28 GMT, leegold2 <le*****@nospam.net> wrote:

This has been done before but not sure how:

Say I have a string of 1000 chars. I want to split the string into two
variables (two array element variables would be OK) one has 200 chars
the other has 800 chars. How would I do this? Must be simple in PHP...

substr

Like:
$d_content1 = substr($d_content,0,100);
$d_content2 = substr($d_content,100);

But, I need it to break the string on the nearest word. I jusr realized
that because I got:

$d_content1 == ....this is really gre
$d_content2 == at

I need it to do:

$d_content1 == ....this is really
$d_content2 == great

Thanks,
Lee G.
Jul 17 '05 #3
.oO(leegold2)
But, I need it to break the string on the nearest word.


http://www.php.net/wordwrap

Micha
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: usgog | last post by:
I need to implement a function to return True/false whether String A contains String B. For example, String A = "This is a test"; String B = "is is". So it will return TRUE if String A includes two...
4
by: William Stacey [MVP] | last post by:
Would like help with a (I think) a common regex split example. Thanks for your example in advance. Cheers! Source Data Example: one "two three" four Optional, but would also like to...
14
by: Ron | last post by:
Hello, I am trying to parse a string on the newline char. I guess vbCrLf is a string constant. How can I parse my string - data - on the newline char? .... data += ASCII.GetString(buffer, 0,...
7
by: lgbjr | last post by:
Hi All, I'm trying to split a string on every character. The string happens to be a representation of a hex number. So, my regex expression is (). Seems simple, but for some reason, I'm not...
11
by: Brian | last post by:
I have been working on a data reception system.. I am still finding my way around Javascript, though I am accomplishing much. I just fixed a flaw that was really hard to find. The symptoms are...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
14
by: tom t/LA | last post by:
Here is a function to convert a CSV file to a Javascript array. Uses idealized file reading functions based on the std C library, since there is no Javascript standard. Not fully tested. ...
3
by: Ondrej Baudys | last post by:
Hi, After trawling through the archives for a simple quote aware split implementation (ie string.split-alike that only splits outside of matching quote) and coming up short, I implemented a...
4
by: dschu012 | last post by:
Ignore the title it isn't exactly what I meant, and after reading it the title sounds kinda stupid. I have an list of numbers as an ascii string that I need to split by a token and store the...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.