i have a text line " as title: news words:500 body: this is a great day
now i want the it be broken into such that 3 parts with the variables holding the data as follows
$title = news
$words = 500
$body = this is a great day
how can i get that? i m trying explode implode but not working here's my code -
<?php
-
$first = array();
-
-
$string = "title: news words:500 body: this is a great day ";
-
$sep1 ="title: ";
-
$sep2 ="words: ";
-
$sep3 ="body: ";
-
-
$first[0] = explode($sep2, $string);
-
$string0 = implode("",$first[0]);
-
$title = $string0;
-
echo $title;
-
-
?>
-
-
-
@angelicdevil -
<?php
-
$first = array();
-
-
$string = "title: news words: 500 body: this is a great day ";
-
$sep1 ="title: ";
-
$sep2 ="words: ";
-
$sep3 ="body: ";
-
-
$body = strstr($string, $sep3);
-
-
-
$string = str_replace ($body ,"", $string);
-
$body = str_replace ($sep3, "", $body);
-
$title = strstr($string, $sep2, true);
-
$string= str_replace ($title, "" , $string);
-
$title = str_replace ($sep1, "", $title);
-
$words= str_replace($sep2, "", $string);
-
-
echo $title . "<br />";
-
echo $body . "<br />";
-
echo $words;
-
-
?>
3 1365 @angelicdevil -
<?php
-
$first = array();
-
-
$string = "title: news words: 500 body: this is a great day ";
-
$sep1 ="title: ";
-
$sep2 ="words: ";
-
$sep3 ="body: ";
-
-
$body = strstr($string, $sep3);
-
-
-
$string = str_replace ($body ,"", $string);
-
$body = str_replace ($sep3, "", $body);
-
$title = strstr($string, $sep2, true);
-
$string= str_replace ($title, "" , $string);
-
$title = str_replace ($sep1, "", $title);
-
$words= str_replace($sep2, "", $string);
-
-
echo $title . "<br />";
-
echo $body . "<br />";
-
echo $words;
-
-
?>
Instead of actually including the words title:, words:, body:, just leave them out and use a specific separator between your items, so if your title is "news", words is 500 and body is "hello world", try this: - $string = "News|500|Hello World!";
-
-
$split = explode("|", $string);
Now your $split variable is an array with these values:
$split[0] = News
$split[1] = 500
$split[2] = Hello World
Use them as you would.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: lawrence |
last post by:
"Garp" <garp7@no7.blueyonder.co.uk> wrote in message news:<_vpuc.1424$j_3.13346038@news-text.cableinet.net>...
> "lawrence" <lkrubner@geocities.com> wrote in message
>...
|
by: Daniel Heiserer |
last post by:
Hi,
I want to fill a string like this:
using namespace std;
string text="
now a lot of text ................
now a lot of text ................
now a lot of text ................
now a lot...
|
by: Bryan Dickerson |
last post by:
I have a string that is delimited, e.g.
"SOD;NAME;ADDRESS1;ADDRESS2;PHONE;CITY;STATE;ZIP;EOD", that I need to strip
off the "SOD;" at the beginning and the ";EOD" at the end. I am well
familiar...
|
by: mouseit101 |
last post by:
I'm writing a program to emulate nuerons (can't spell for my life
sorry) and am using an array of "mailboxes" to propagate messages
through the network, but I need to be able to remove the request...
|
by: flameboy |
last post by:
I am currently trying to figure my way how to output strings to a file.
I have seen all the many posts and such how to do it in a console program, and have had much success doing it that way. This...
|
by: InDepth |
last post by:
Now that .NET is at it's fourth release (3.5 is coming soon), my very humble
question to the gurus is:
"What have we won with the decision to have string objects immutable? Or did
we won?"
...
|
by: deerchao |
last post by:
Hi, I'd like to render colorful text with word wrap on screen (kind of
inline <fonttag to change text color in html), but run into the line
break problem.
Graphics provides several DrawString...
|
by: TVining |
last post by:
I want to remove all text in a single field that matches "Army & Air Force Hometown News
News Release
123 System St. (210)123-3333 Fax: (210)123-2222
San Antonio, TX...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
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)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
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
| |