473,785 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_ass oc($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_H ERE($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 4871
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_ass oc($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_H ERE($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_ass oc($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_H ERE($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
3505
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 of the ones I looked, classified by how I would rewrite them (if I could): * Rewritable as def statements (<name> = lambda <args>: <expr> usage) These are lambdas used when a lambda wasn't needed -- an anonymous function was created with...
121
10180
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 support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather than a PHP IDE. It only supports basic IntelliSense (or code completion) and doesn't have anything...
7
23555
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. Execution is faster. Where will it be stotred?(Is it in bss/stack/?) FUNCTION:
3
10529
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
2021
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 char{'^','^'}) for the rows but for some reason i get an empty cell between each result, this is also in the documentation, i just don't know why?
4
3854
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, that the split method and the regex.replace method was better than the string.replace method and replace function. I did not believe that.
11
4441
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 the code if someone could help... strID = split(request.form("proj"), ", ") projstat = split(request.form("rojstat"),",") impr = split(request.form("impr"),",") idate =...
2
3173
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 i change something in php file using in ajax function.it not refreshed,means its shows the previous result it not get updated.i can't understand whats the prob.this is the code i m using: <? include("config.inc.php"); //error_reporting(0); ...
3
1846
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 geocoded postcode. If the point is less than 5 miles away, I then put a point on the map. My code is here: function createMarker(point,html) { // FF 1.5 fix html = '<div style="white-space:nowrap;">' + html + '</div>'; ...
0
9483
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10346
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10157
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10096
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8982
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.