473,395 Members | 1,694 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,395 software developers and data experts.

what function will split text

Hi,
I need a function that will divide text from mysql in 2 parts, so that I
can display first half in one column and second half in second column.
I can't find what function will do this job.
Here is part of what I have.

$myrow = mysql_fetch_assoc($rsindexpage);
//function wordcount
$wc = str_word_count($myrow);
$half = ($wc/2);
//function divide text in two columns
<tr>
<td width="150" valign="top">
<?php
$str = $myrow;
$split = NEED_FUNCTION_HERE($str, $half);
$first = $split[0];
$second = $split[1];
echo "$first";
?>
</td>
<td width="150" valign="top">
<?php
echo "$second";
?>
</td>
</tr>
Sep 30 '06 #1
3 4838
ashok wrote:
Hi,
I need a function that will divide text from mysql in 2 parts, so that I
can display first half in one column and second half in second column.
I can't find what function will do this job.
Here is part of what I have.

$myrow = mysql_fetch_assoc($rsindexpage);
//function wordcount
$wc = str_word_count($myrow);
$half = ($wc/2);
//function divide text in two columns
<tr>
<td width="150" valign="top">
<?php
$str = $myrow;
$split = NEED_FUNCTION_HERE($str, $half);
$first = $split[0];
$second = $split[1];
echo "$first";
?>
</td>
<td width="150" valign="top">
<?php
echo "$second";
?>
</td>
</tr>

Look at the substr function. The syntax is:

substr(<string name>, <start position>, <length>)

so, assuming a string of length 150 that you
want to split into two equal parts:

$first = substr($str, 0, 75);
$second = substr($str, 75, 75);

HTH

Jerry
Sep 30 '06 #2
ashok wrote:
Hi,
I need a function that will divide text from mysql in 2 parts, so that I
can display first half in one column and second half in second column.
I can't find what function will do this job.
Here is part of what I have.

$myrow = mysql_fetch_assoc($rsindexpage);
//function wordcount
$wc = str_word_count($myrow);
$half = ($wc/2);
//function divide text in two columns
<tr>
<td width="150" valign="top">
<?php
$str = $myrow;
$split = NEED_FUNCTION_HERE($str, $half);
$first = $split[0];
$second = $split[1];
echo "$first";
?>
</td>
<td width="150" valign="top">
<?php
echo "$second";
?>
</td>
</tr>

Is this text a fixed-length, or is there a delimiter of some kind?

If there is a delimiter, consider explode:
http://us3.php.net/manual/en/function.explode.php

Oct 2 '06 #3
In article <ef***********@news.mtu.ru>, as***@replyhere.com says...
Hi,
I need a function that will divide text from mysql in 2 parts, so that I
can display first half in one column and second half in second column.
I can't find what function will do this job.
It may or may not be overkill, depending on the complexity of the
delimiter and your split, but my first thought went to using preg_match
and assigning the $matches array. Then use sub-expressions (parenthesis)
to extract the parts you need. I use this all the time to, say, batch-
convert a a bunch of web pages for inclusion in a database, with header
field like metatag keywords and description extracted nicely.

Just give a shout here if you'd like to see some sample code, and I'll
see if I can hunt it down.

Later
GC
Oct 6 '06 #4

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

Similar topics

26
by: Steven Bethard | last post by:
I thought it might be useful to put the recent lambda threads into perspective a bit. I was wondering what lambda gets used for in "real" code, so I grepped my Python Lib directory. Here are some...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
7
by: Newbie_sw2003 | last post by:
Where should I use them? I am giving you my understandings. Please correct me if I am wrong: MACRO: e.g.:#define ref-name 99 The code is substituted by the MACRO ref-name. So no overhead....
3
by: Reb | last post by:
Hi, I could split only by a character. How do i split by a string. How can i do something like this. e.g., somestring.Split("name"); Thanks Reb
2
by: Elhanan | last post by:
hi all.. i have the following string: 200850625~01~464~^^200850625~01~464~^^200850625~01~908~^^ which i will need to turn to a mutli-dimentional string array i used result.Split(new...
4
by: Cor | last post by:
Hi Newsgroup, I have given an answer in this newsgroup about a "Replace". There came an answer on that I did not understand, so I have done some tests. I got the idea that someone said,...
11
by: pmarisole | last post by:
I am trying to use the vbscript "split" function on a multi-select field. I am trying to do a mass update of several records at a time. I am getting an error and I'm not sure what to do. Here is...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
3
pezholio
by: pezholio | last post by:
Hi, I'm having a bit of trouble using Google Maps and the Google Ajax Search API, I'm trying to take a postcode, geocode it and then calculate the distance between the that postcode and a second...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.