473,406 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Formating this string

I receive string like this:
"aaa.bbb.ccc.com <20000>"

I need to get only number 20000.
How can I get numbers betwwen the "<>"

Thanks
Jul 17 '05 #1
5 1223
$pattern = "*\<[0-9]+\>*";
$in = "aaa.bbb.ccc.com <20000>";

preg_match($pattern, $in, $matches);
$out = trim($matches[0], "<>"); //$out now has '20000'

I'm not much of a regexp guy, so there might be a cleaner pattern.
Nonetheless, that should work.

Jul 17 '05 #2
ZeldorBlat wrote:
$pattern = "*\<[0-9]+\>*";
$in = "aaa.bbb.ccc.com <20000>";

preg_match($pattern, $in, $matches);
$out = trim($matches[0], "<>"); //$out now has '20000'

I'm not much of a regexp guy, so there might be a cleaner pattern.
Nonetheless, that should work.

Thank You
Jul 17 '05 #3
ZeldorBlat wrote:
$pattern = "*\<[0-9]+\>*";
$in = "aaa.bbb.ccc.com <20000>";

preg_match($pattern, $in, $matches);
$out = trim($matches[0], "<>"); //$out now has '20000'

I'm not much of a regexp guy, so there might be a cleaner pattern.
Nonetheless, that should work.


$in = "aaa.bbb.ccc.com <20000>";
$pattern = "/$.*\<(\d+)\>.*^/";
$out = preg_replace($pattern, "$1", $in);

I didn't test this, but I attempt to "drop everything from the beginning
of string up until '<' and after '>'".

--
Markku Uttula
Jul 17 '05 #4
while everyone's code works..
(actually, I'm not sure about the examples with \< and \> in the
expression... "<" and ">" need not be escaped. )

anyhow, here's my take:

$string = 'aaa.bbb.ccc.com <20000>';
if ( preg_match('/<(\d+)>/',$string,$matches) )
$num = $matches[1]; // $num in this example is now '20000'
else {
// no num inside <> found
}

Jul 17 '05 #5
Markku Uttula wrote:
ZeldorBlat wrote:
$pattern = "*\<[0-9]+\>*";
$in = "aaa.bbb.ccc.com <20000>";

preg_match($pattern, $in, $matches);
$out = trim($matches[0], "<>"); //$out now has '20000'

I'm not much of a regexp guy, so there might be a cleaner pattern.
Nonetheless, that should work.

$in = "aaa.bbb.ccc.com <20000>";
$pattern = "/$.*\<(\d+)\>.*^/";
$out = preg_replace($pattern, "$1", $in);

I didn't test this, but I attempt to "drop everything from the beginning
of string up until '<' and after '>'".

Ok, try and adhere to the KISS philosophy. Observe.

$in = 'aaa.bbb.ccc.com <20000>';

$in = preg_replace('/<([0-9]+)>/', '$1', $in);

$in will now contain '2000'
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: rodrigo guerra | last post by:
where i can change the code formating that visual studio does in the code.... like if i type: if ( ) { .... } visual studio changes to:
4
by: djc | last post by:
Is there a property or method of the textbox web server control that I can use to format the text in it a certian way. For example I am displaying a date value from a database in a text box. It...
3
by: Tina | last post by:
I have a datagrid where I specified {0:###,###,###} at design time. However sometimes I am putting percentages in the grid instead of money and I want to change the formating to {##%}. I've...
3
by: Smiley | last post by:
Hi, I know how to do confitional formating in Excel by clicking the wizard. Is this possible in MS Access ? If so, please directly where to look. I found example but nothing as to how to do it....
12
tolkienarda
by: tolkienarda | last post by:
hi all I am working on a content management service and i need some help keeping formating. what i am doing is recreating my site in an admin side and all of the articles on the site will...
1
by: Shawn Northrop | last post by:
I just read an article on kirupa.com about incorporating mySQL and PHP with flash. I am dynamically loading conent into a flash movie and am not sure how to format. In my php code i have: $y = "";...
0
by: Fonix | last post by:
I'm trying to make table border with pyExcelerator. As i can see there is only cell formating!? If i'm wrong pls tell me what is method to make more then one cell to have same format, other then...
2
by: sitko | last post by:
Hi, I'm in the process of converting a VB.net program into a C program so it can run on a unix like machine. I've been moving along at a nice pace, but this conversion has stumped me. I need...
1
by: nico | last post by:
Hi, I need to do a lot of string formating, and I have strings and/or unicode strings and when I do the following: "%s %s" % (u'Salut', 'H\xe4llo'), I get an exception : UnicodeDecodeError:...
4
by: =?Utf-8?B?QnJhc3NpY2FOaWdyYQ==?= | last post by:
Greetings, I am writing an application that prepares a quotation for a customer. The calculations are done in a SQL Server stored procedure. I use a datareader to fetch the record, but cannot...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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
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...
0
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,...
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
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...
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,...

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.