473,471 Members | 2,089 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Explode

The1corrupted
134 New Member
I have a question about the explode function and am rather confused...
Say $msg=I like Corn
If I have [PHP]<?php
$mesg=explode(" ", $msg, 3);
echo $mesg[0].$mesg[2];
?>[/PHP]
will I manage to be able to pull this result:
"I like"?
Feb 27 '07 #1
3 1447
ronverdonk
4,258 Recognized Expert Specialist
What you are echoeing in your sample is "ICorn" because you used the first (msg[0]) and the third (msg[2]) entries without connecting blank character.

In order to display "I like" your do[php]echo $mesg[0].' '.$mesg[1];[/php]

Ronald :cool:
Feb 28 '07 #2
The1corrupted
134 New Member
Ah... Also, can I double explode strings? Say...

[PHP]
<?php
$mesg=explode(" ", $msg, 2);

if ($mesg[0]=="word") {
$mesg=explode(" ", $msg, 3);
}

?>[/PHP]
Or would I have to redefine $mesg in the if statement as another variable?
Mar 1 '07 #3
r035198x
13,262 MVP
Ah... Also, can I double explode strings? Say...

[PHP]
<?php
$mesg=explode(" ", $msg, 2);

if ($mesg[0]=="word") {
$mesg=explode(" ", $msg, 3);
}

?>[/PHP]
Or would I have to redefine $mesg in the if statement as another variable?
Use another variable for the array

Expand|Select|Wrap|Line Numbers
  1.  <?php 
  2. $mesgArray1=explode(" ", $msg, 2);
  3.  
  4. if ($mesgArray1[0]=="word") {
  5. $mesgArray2=explode(" ", $msg, 3);
  6. }
  7. ?>
  8.  
The value of $msg remains the same in this case
Mar 2 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Rob Gudgeon | last post by:
Hi Is it possible to explode a string into an array using more than one separator? I have database records that contain several values, mostly split by semi-colons but some older records are...
6
by: William Krick | last post by:
I have a string containing concatenated ascii "records" that are each terminated by '\n'. For testing purposes, I construct sample data like this... $mystring =...
4
by: Richard Lawrence | last post by:
Hi there, I'm having a problem with PHP which I'm not sure how to best solve. Here is the code: $fp = fopen("comments.txt", "r"); while(!feof($fp)) { $line = fgets($fp, 1024); list($key,...
12
by: frizzle | last post by:
Hi there, i have a site with fake folders & files. htaccess rewrites everything to index.php?vars now in index.php i decide what file to include with a switch/case statement. to define where...
5
by: FFMG | last post by:
Hi, I need the php equivalent of explode in one of my app. I read a very big file and "explode" each line to fill a structure. The reading of the file, 19Mb, (I will also need to streamline...
0
by: k04jg02 | last post by:
Python has a nifty operator that will take a container and pass its elements as function parameters. In Python you can make a list like so: x = Then you can say: f(*x)
4
by: Davide | last post by:
Hi All, I'm trying to use explode to separate the result of a textual file, but it explode me only the first row. the foo.txt is pippo pluto pluto pippo pippo pippo .... I use this script...
8
by: Jack | last post by:
I would like to Explode a string into an array that does not begin at 0 but I can't get it to work. For example: $MyInfo = array(1 =27,68,31,19,40); will result in $MyInfo = 27 ... $MyInfo = 40...
5
by: sathyashrayan | last post by:
Dear group, The function to be used as follows: $links = "http://www.campaignindia.in/feature/analysis"; $tag1 = '<div class=feature-wrapper>'; $tag2 = '<h1><a href'; $tag3 = "</a>"; $op =...
8
by: vinpkl | last post by:
hi all i want to use explode url for shotening my urls i have a url like http://localhost/vineet/products.php?dealer_id=12&category_id=2 This is my navigation php code that has url...
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
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
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
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.