Hi,
I have a shell script to build components of a product. The follow snippet will explain what I am doing.
# !/bin/sh
for choice in "$@" ;
do
case $choice in
"o") echo "Calling $choice" ; o ;;
"i") echo... (8 Replies)
Hello, if I have a file containing a chunk of HTML and I want to extract
always the string beginning http://www.xxx.com/v/ that ends just before "> (i.e. and including the bit BqqtJpfZElQ&hl will change randomly)
Any ideas???
# cat randomfeature.html
<object width="160"... (3 Replies)
Hi Everyone,
I stored the result of a certain awk script in the variable arr.The result is /inets /banking /tools.
arr= /inets /banking /tools
These are 3 direcctories. I should be able to move in to these directories using "cd" command.Can you tell me how to extract... (5 Replies)
Hi, I am a new bee to this forum.
I am trying to extract the text after a matching pattern from a url using regular expression.
Ex: http://locatlhost:2020/proxy/checkthisout
I want to extract the string after proxy/. I am not familiar with reg ex. Can someone please help? (2 Replies)
I have a string stored in a variable. For instance,
$str = " Opcode called is : CM_OP_xxx "
where xxx changes dynamically and can be either LOGIN or SEARCH..... depends on runtime.
For example :
$str = " Opcode called is : CM_OP_SEARCH "
$str = " Opcode called is : CM_OP_LOGIN "
I... (3 Replies)
Hi,
I'm trying to extract the middle of an array that is of
variable length but always has a first and last common
element,
The following works OK...
#!/bin/bash
ARRAY='switch'
ARRAY='option1'
ARRAY='option2'
ARRAY='option3'
ARRAY='value'
SWITCH=${ARRAY:0:1}
VALUE=${ARRAY:(-1)}... (1 Reply)
I have more than 1000 files to parse. Each file contains few lines (number of lines varies) followed by a header line having all column's name (SPOT, NAME etc) and then values for those columns.
**Example File:
sdgafh
dfhaadfha
sfgaf dhah jkthdj
SPOT NAME GENE_NAME CH_MEAN CHDN_MED ... (11 Replies)
#!/usr/bin/ksh
set -x
testfile=my.test.file.flag
echo ${testfile: (-4)}
#/home/maldohe/scripts/spawn1&
sleep 3
echo myspawn is now ending
exit
Background:
I am trying to extract the word flag from anf given file name. This is a demo script that I am working on to fix a production issue.... (8 Replies)
Hi,
Log file will contain text like below:
May 7 14:12:09 nap_fujitsu-nexus_pbb-denek-01-r_DE.de.ignite.net 108767: 115673: May 7 14:12:08: %RTT-3-IPSLATHRESHOLD: IP SLA Monitor(112): Threshold below for rtt
May 8 14:12:09 nap_fujitsu-nexus_pbb-denek-01-r_DE.de.ignite.net 108767: 115673:... (3 Replies)
I am trying to extract a time from the below string in perl but not able to get the time properly
I just want to extract the time from the above line I am using the below syntax
x=~ /(.*) (\d+)\:(\d+)\:(\d+),(.*)\.com/
$time = $2 . ':' . $3 . ':' . $4;
print $time
Can... (1 Reply)
Discussion started by: karan8810
1 Replies
LEARN ABOUT PHP
explode
EXPLODE(3) 1 EXPLODE(3)explode - Split a string by stringSYNOPSIS
array explode (string $delimiter, string $string, [int $limit])
DESCRIPTION
Returns an array of strings, each of which is a substring of $string formed by splitting it on boundaries formed by the string $delimiter.
PARAMETERS
o $delimiter
- The boundary string.
o $string
- The input string.
o $limit
- If $limit is set and positive, the returned array will contain a maximum of $limit elements with the last element containing the
rest of $string. If the $limit parameter is negative, all components except the last -$limit are returned. If the $limit parame-
ter is zero, then this is treated as 1.
Note
Although implode(3) can, for historical reasons, accept its parameters in either order, explode(3) cannot. You must ensure that the
$delimiter argument comes before the $string argument.
RETURN VALUES
Returns an array of strings created by splitting the $string parameter on boundaries formed by the $delimiter.
If $delimiter is an empty string (""), explode(3) will return FALSE. If $delimiter contains a value that is not contained in $string and a
negative $limit is used, then an empty array will be returned, otherwise an array containing $string will be returned.
CHANGELOG
+--------+-----------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+-----------------------------------------+
| 5.1.0 | |
| | |
| | Support for negative $limits was added |
| | |
+--------+-----------------------------------------+
EXAMPLES
Example #1
explode(3) examples
<?php
// Example 1
$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode(" ", $pizza);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2
// Example 2
$data = "foo:*:1023:1000::/home/foo:/bin/sh";
list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);
echo $user; // foo
echo $pass; // *
?>
Example #2
explode(3) return examples
<?php
/*
A string that doesn't contain the delimiter will simply
return a one-length array of the original string.
*/
$input1 = "hello";
$input2 = "hello,there";
var_dump( explode( ',', $input1 ) );
var_dump( explode( ',', $input2 ) );
?>
The above example will output:
array(1)
(
[0] => string(5) "hello"
)
array(2)
(
[0] => string(5) "hello"
[1] => string(5) "there"
)
Example #3
$limit parameter examples
<?php
$str = 'one|two|three|four';
// positive limit
print_r(explode('|', $str, 2));
// negative limit (since PHP 5.1)
print_r(explode('|', $str, -1));
?>
The above example will output:
Array
(
[0] => one
[1] => two|three|four
)
Array
(
[0] => one
[1] => two
[2] => three
)
NOTES
Note
This function is binary-safe.
SEE ALSO preg_split(3), str_split(3), mb_split(3), str_word_count(3), strtok(3), implode(3).
PHP Documentation Group EXPLODE(3)