Hello,
I am trying to split a string that contains parentheses; the aim here is
to keep the part that's before the opening parenthese:
the string (quoted here) is "36 (72 cm)"
First I want to know if the string contains at least an openning
parenthese; if it does, I split it and extract the first token (ie "36 ").
My code follows
if (preg_match("/\(/", $sPermutationName)) {
$tokens = explode("\(", $sPermutationName);
$sPermutationName = $tokens[0];
}
but that does not work. Would anyone care to enlighten me on this one? 3 1727
On 24 Sep, 13:52, Henri <h...@dontbother.fuwrote:
Hello,
I am trying to split a string that contains parentheses; the aim here is
to keep the part that's before the opening parenthese:
the string (quoted here) is "36 (72 cm)"
First I want to know if the string contains at least an openning
parenthese; if it does, I split it and extract the first token (ie "36 ").
My code follows
if (preg_match("/\(/", $sPermutationName)) {
$tokens = explode("\(", $sPermutationName);
$sPermutationName = $tokens[0];
}
but that does not work. Would anyone care to enlighten me on this one?
"does not work", ahh how helpful! That tells us exactly what you are
actually seeing - NOT!!!
As a matter of interest, why are you exploding on "\(", when \ doesn't
appear in the target string?
Henri wrote:
Hello,
I am trying to split a string that contains parentheses; the aim here is
to keep the part that's before the opening parenthese:
the string (quoted here) is "36 (72 cm)"
First I want to know if the string contains at least an openning
parenthese; if it does, I split it and extract the first token (ie "36 ").
My code follows
if (preg_match("/\(/", $sPermutationName)) {
$tokens = explode("\(", $sPermutationName);
$sPermutationName = $tokens[0];
}
but that does not work. Would anyone care to enlighten me on this one?
Hi Henri
regular expressions would be on overkill here.
strtok($a, "(")
does exactly what you want - returns a portion of the string before "(".
If there's no "(" , the whole string will be returned.
--
gosha bine
extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
On Mon, 24 Sep 2007 06:31:28 -0700, Captain Paralytic wrote:
On 24 Sep, 13:52, Henri <h...@dontbother.fuwrote:
>Hello,
I am trying to split a string that contains parentheses; the aim here is to keep the part that's before the opening parenthese:
the string (quoted here) is "36 (72 cm)" First I want to know if the string contains at least an openning parenthese; if it does, I split it and extract the first token (ie "36 "). My code follows
if (preg_match("/\(/", $sPermutationName)) { $tokens = explode("\(", $sPermutationName); $sPermutationName = $tokens[0];
}
but that does not work. Would anyone care to enlighten me on this one?
"does not work", ahh how helpful! That tells us exactly what you are
actually seeing - NOT!!!
mmh... forgive me. What I clumsily tried to mean is that the preg_match
did not seem to see any parenthese in the string and therefore did not
execute the two following statements.
As a matter of interest, why are you exploding on "\(", when \ doesn't
appear in the target string?
because I thought that escaping the parenthese would avoid a compilation
error due to the code's being misinterpreted (ie: reporting a parenthese
mismatch).
Anyway, I think I have a solution now. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: fartsniff |
last post by:
hello all,
here is a preg_match routine that i am using. basically, $image is set in
some
code above, and it can be either st-1.gif or sb-1.gif (actually it randomly
picks
them from about 100...
|
by: Han |
last post by:
I'm wondering if someone can explain why the following works with
preg_match_all, but not preg_match:
$html = "product=3456789&"
preg_match_all ("|product=(\d{5,10})&|i", $html, $out);
$out...
|
by: Mark Woodward |
last post by:
Hi all,
I'm trying to validate text in a HTML input field.
How do I *allow* a single quote?
// catch any nasty characters (eg !@#$%^&*()/\)
$match = '/^+$/';
$valid_srch = preg_match($match,...
|
by: mantrid |
last post by:
Hello
Found this piece of code using preg_match to check file types during upload
of files.
$allowed_file_types = "(jpg|jpeg|gif|bmp|png)";
preg_match("/\." . $allowed_file_types . "$/i",...
|
by: cainwebdesign |
last post by:
I need to create a simple page to find the .gif file below from the
page below. No matter what I try it doesn't work.... Any ideas?
http://www.toysrus.com/product/index.jsp?productId=2327085
...
|
by: jsamdirect |
last post by:
I am having a weird issue with php preg_match. I am moving to my php
sites to a new server. On the old server all works well. On the new
server preg_match always returns false. If I log in via ssh...
|
by: JanDoggen |
last post by:
function vldLicense($lic)
{
echo "called with lic: ". $lic . "<br>";
echo preg_match('', $lic) . "<br>";
if (preg_match('{4}-{4}-{4}-{4}', $lic) == 0) return false;
return true;
}
gives me:
|
by: chadsspameateremail |
last post by:
I might have found a problem with how preg_match works though I'm not
sure.
Lets say you have a regular expression that you want to match a string
of numbers. You might write the code like this:...
|
by: Thomas Mlynarczyk |
last post by:
Hello,
I want to split a given string into tokens which are defined by regexes:
// example tokens - a bit more complex in real
$tokens = array(
'NUMBER' ='~^\d+~',
'NAME' ='~^+~',
'ANY' ...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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...
| |