473,396 Members | 1,846 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,396 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 3248
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.