f



Question on PHP regular expressions

In PHP I have many more options for functions that do regular
expression than I did in Perl.  My question is what is the best one to
use for doing the following:

Give the following:
{Somestring.somestring.somestring} blah blah {somestring} value here
not used {more.text.here}

I want an array like the following:
[0] => Somestring.somestring.somestring
[1] => somestring
[2] => more.text.here

So basically I just want to capture the contents (alpha-numeric +
periods) inside of curly braces.

Thanks for any help.

0
sean771 (39)
11/8/2007 7:05:11 PM
comp.lang.php 32646 articles. 0 followers. Post Follow

2 Replies
563 Views

Similar Articles

[PageSpeed] 21

sberry <sean@buildingonline.com> writes:

> In PHP I have many more options for functions that do regular
> expression than I did in Perl.  My question is what is the best one to
> use for doing the following:
>
> Give the following:
> {Somestring.somestring.somestring} blah blah {somestring} value here
> not used {more.text.here}
>
> I want an array like the following:
> [0] => Somestring.somestring.somestring
> [1] => somestring
> [2] => more.text.here
>
> So basically I just want to capture the contents (alpha-numeric +
> periods) inside of curly braces.
>
> Thanks for any help.

This should get you started:

$string = "{Somestring.somestring.somestring} blah blah 
  {somestring} value here not used {more.text.here}";
$pattern = '/\{.+?\}/';
preg_match_all($pattern, $string, $matches);
print_r($matches);

Hope that helps,
0
c.groner (76)
11/8/2007 7:17:10 PM
On Nov 8, 11:17 am, Carl <c.gro...@gmail.com> wrote:
> sberry <s...@buildingonline.com> writes:
> > In PHP I have many more options for functions that do regular
> > expression than I did in Perl.  My question is what is the best one to
> > use for doing the following:
>
> > Give the following:
> > {Somestring.somestring.somestring} blah blah {somestring} value here
> > not used {more.text.here}
>
> > I want an array like the following:
> > [0] => Somestring.somestring.somestring
> > [1] => somestring
> > [2] => more.text.here
>
> > So basically I just want to capture the contents (alpha-numeric +
> > periods) inside of curly braces.
>
> > Thanks for any help.
>
> This should get you started:
>
> $string = "{Somestring.somestring.somestring} blah blah
>   {somestring} value here not used {more.text.here}";
> $pattern = '/\{.+?\}/';
> preg_match_all($pattern, $string, $matches);
> print_r($matches);
>
> Hope that helps,

Thanks.  That is exactly what I wanted to do.  I just added the
PREG_OFFSET_CAPTURE so I could also track the string offsets of the
matches.

0
sean771 (39)
11/8/2007 7:27:10 PM
Reply:

Similar Artilces:

PHP regular expressions
Hello, I am writing an elearning software with php. I need a script to recognize any inut of the type ab,aabb,aaabbb,aaaabbbb..... And so on. Could anyone tell me how can I do this using regular expressions? Regards, Albert Achtenberg Albert <albert@arbel-designs.com> wrote: > I am writing an elearning software with php. I need a script to > recognize any inut of the type ab,aabb,aaabbb,aaaabbbb..... And so on. > Could anyone tell me how can I do this using regular expressions? So basically you need a regexp tutorial. I don't know any but studing http://nl.php.net/manual...

PHP Training Institute In Delhi, Live Projects on PHP. Short Term PHP Courses, PHP Scripts, PHP Training with Live Projects.
Vserve Global offers short term PHP: Hypertext Preprocessor Training Course, which is a widely used, general-purpose scripting language that was originally designed for web development, to produce dynamic web pages. It can be embedded into HTML and generally runs on a web server, which needs to be configured to process PHP code and create web page content from it. It can be deployed on most web servers and on almost every operating system and platform free of charge.PHP is installed on over 20 million websites and 1 million web servers. TOPICS:- >> Core PHP Language >> HTML, Cascad...

php outside php (?)
Sounds weird, i know. What i want/wonder is the following: PHP can do the next: <?php if($foo == 'bar') { ?> Ow yeah, foo is bar! <?php }; ?> But how can i do the following: <?php $foo= ?> this is what foo looks like. <?php }; ?> This way i could edit the content of $foo in DW's design-view. I hope it's clear enough for you all to understand... Greetings frizzle. frizzle wrote: > But how can i do the following: > > <?php > > $foo= > > ?> > this is what foo looks like. > <?php > > }; > > ?> > > This way i could edit the content of $foo in DW's design-view. > I hope it's clear enough for you all to understand... <?php ob_start(); ?> this is what foo looks like. <?php $foo=ob_get_clean(); ?> -- Justin Koivisto - justin@koivi.com http://koivi.com Wow, little late on the reply, but i still wanted to thank you for your help. This is exactly what i meant, and it works great! :D Thanks again. ...

PHP within PHP...
I took over the support of a website that is set up something like this inside one of the pages: include_once("header.php"); <?php //to get the content of the page they do this: $content = mysql_query("select content etc...); echo $content; ?> include_once("footer.php"); I am having problems evaluating any php that is used in the mysql content. Is there a way to get the mysql withing the mysql to run? Thank you for your time, Mandragon On Sep 17, 12:56 pm, Mandrago...@gmail.com wrote: > I took over the support of a website that is set up something like > this inside one of the pages: > > include_once("header.php"); > > <?php > //to get the content of the page they do this: > $content = mysql_query("select content etc...); > > echo $content; > ?> > > include_once("footer.php"); > > I am having problems evaluating any php that is used in the mysql > content. Is there a way to get the mysql withing the mysql to run? > > Thank you for your time, > > Mandragon Sorry, The question should read: "Is there a way to get the php withing the echo $htmlcontent to run?" Of course you are, $content is a resource. The MySQL Query resource. try this: $content = mysql_query('bla bla bla'); while ($row = mysql_fetch_assoc($content)) { $result[] = $row; } $content = $result; Now you can use $content ;). In answer to your edit... eval($co...

php to php obj
Hi All, Is there any tool to convert the .php files into its object files in deploying the files to other's server like java classes are deployed? Thanks in advance --AR John7481 <arjohn7481@hotmail.com> wrote or quoted: > Is there any tool to convert the .php files into its object files in > deploying the files to other's server like java classes are deployed? To what end? Do you want a PHP obfuscator? They tend not to be needed - since the code remains on the server. Do you want a PHP squeezer? Again - since PHP remains on the server that is of reduced importance. PHP obfuscators and squeezers are out there - but what exactly are you looking for? -- __________ |im |yler http://timtyler.org/ tim@tt1lock.org Remove lock to reply. With total disregard for any kind of safety measures Tim Tyler <tim@tt1lock.org> leapt forth and uttered: > John7481 <arjohn7481@hotmail.com> wrote or quoted: > >> Is there any tool to convert the .php files into its object >> files in deploying the files to other's server like java >> classes are deployed? > > To what end? > > Do you want a PHP obfuscator? They tend not to be needed - > since the code remains on the server. > > Do you want a PHP squeezer? Again - since PHP remains on the > server that is of reduced importance. > > PHP obfuscators and squeezers are out there - but what exactly > are you looking for? I think he'...

Regular expression example on PHP.net
Howdy folks, On this page at php.net http://www.php.net/features.http-auth there's a regular expression in Example 34.2. It's supposed to parse out the different values being passed in the header. I know what it's supposed to do, so I have a vague idea of what's being done in the RE, but I've been having a heck of a time figuring out what each part of the RE is actually doing. Here's what I have so far: preg_match_all('@(\w+)=(?:([\'"])([^\2]+)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER); //'@ //(\w+) Any word character (letter/digit/_), 1 or more //= Equal sign //(?: This submatch will not be captured (still available for later matching) //([\'"]) A single or double quote //([^\2]+) Not start of text (STX)?, 1 or more //\2| //([^\s,]+) Not whitespace or comma, 1 or more //) //@' I'm unclear as to what the second \2 does, as well as which parts the OR applies to. And what are the @s for? Thanks for any help, ZF -- Posted via a free Usenet account from http://www.teranews.com On Fri, 07 Sep 2007 08:02:07 +0200, Zenofobe <fake_email@fake_domain.com= > = wrote: > Howdy folks, > > On this page at php.net > http://www.php.net/features.http-auth > there's a regular expression in Example 34.2. It's supposed to parse = out > the different values being passed in the header. I know what it's > supposed to do, so I have a vague i...

Converting PERL regular expression to PHP?
Hi, I'm in the process of converting some PERL to PHP. Thus, is it possible to leave the following line as is: if ($id =~ /vvvvv/g) { ... } If not, can someone provide PHP equivalent? BTW, I have checked the syntax using 'php -l' because I'm not an expert of PERL but I'm using various references to do the conversion. However, I was able to locate this particular construct. Thanks in advance, -Conrad Hi, the last couple of sentences should read: If not, can someone provide PHP equivalent? BTW, I have checked the syntax using 'php -l'. Also, I'...

Regular Expression for replacing images through URLs in PHP
Hi! I want to replace images through URLs with the help of a regular expression. For example: <img src='http://xxxxx.net/photo/small.jpg'> should be replaced through: <a href='http://xxxxx.net/photo/small.jpg'>Link</a> Another problem are emoticons, which are also included as <img>. Therefore I would like to extend the upper regular expression that the image should only be replaced through an URL, if the src attribute of the img tag does not start with "/modules/emoticons/". Thanks in advance, Markus On Tue, 19 Jul 2005 10:31:30 +02...

Best PHP Training | PHP Development Training | PHP Training Institute
Tops Technologies provides php and mysql certification courses in ahmedabad, baroda, surat, Rajkot, Udaipur, Gujarat, india.PHP Training with MySQL is an introductory course in the PHP and MySQL technology. Mysql and php training course, php for beginners, sql training courses, PHP Training courses, php courses, mysql training courses, php mysql course. For More Details :- http://www.tops-int.com ...

php regular expression doesn't match
Hi PHP's regular expression look like doesn't support .*? syntax. So i cannot match the shortest match. For exmaple: $str="a1b a3b"; $str1=ereg_replace("a.*b", "peter", $str1); will produce "peter", but i want "peter peter", so how to? thanks from Peter (cmk128@hotmail.com) cmk128@hotmail.com wrote: > Hi Hi, > PHP's regular expression look like doesn't support .*? syntax. So i > cannot match the shortest match. For exmaple: > > $str="a1b a3b"; Typo. That was $str1="a1b a3b" I expect. > $str1=ereg_replace("a.*b", "peter", $str1); > will produce "peter", but i want "peter peter", so how to? > Yes, * is greedy. I do not know your real-world example, but maybe using a wordboundary can solve your problem? eg: $str1=ereg_replace("/a.*b\b/", "peter", $str1); > thanks > from Peter (cmk128@hotmail.com) > Regards, Erwin Moller Erwin Moller wrote: > cmk128@hotmail.com wrote: >> Hi > > Hi, > >> PHP's regular expression look like doesn't support .*? syntax. So i >> cannot match the shortest match. For exmaple: >> >> $str="a1b a3b"; > > Typo. That was $str1="a1b a3b" I expect. > >> $str1=ereg_replace("a.*b", "peter", $str1); >> will produce "peter", but i want "p...

Send array from php to php
HI every one I' try to send array from web page to php file but no data are show I'm using session to store data and this is my code //////////////////////////////////////////////////////////////////////// $data = $cart_items; session_register('data'); foreach ($cart_items as $cart_item) { echo "<tr>"; echo " <td><span class='style2'>".$cart_item->name."</span></td>"; echo " <td><span class='style2'>".$cart_item->description."</ span></td>"; echo " <td><span class='style2'>".$cart_item->price." S.R.</span></ td>"; echo " <td><span class='style2'>".$cart_item->quantity."</span></ td>"; echo " <td><span class='style2'>".$cart_item->price * $cart_item- >quantity."</span></td>"; echo " <td><span class='style4'><a href='order.php?action=del&id=". $cart_item->object_id."'>[del]</a></span></td>"; echo "</tr>"; \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \ and this is my php code to get the data //////////////////////////////////////////////////////// <?php foreach ($data as $item) { echo "<tr>"; print " &l...

php notification through php sdk
Hi there I want to build a e-commerce website similar to wish.com and I have chosen opencast as my framework of choice. Now wish has a feature that when you save a product in wish and if you are logged in with Facebook or gmail all of your friends will get a notification that your friends has saved a item on wish. I want a similar feature on my site Now I know Facebook provide a sdk JavaScript and php and wish might be using something similar but I am using open cart can I open home page or product page in the sdk Thanks On 3/20/2015 7:30 AM, apoorv.kanungo@gmail.com wrote: &g...

PHP does not parse .PHP files
I have this problem with PHP that someone might be able to help. With CLI, I am able to execute my .php files. For example, if I type "php phpinfo.php" , this works fine on my system. If I put the phpinfo.php file is in /var/www/html and I try to access it through the browser, I get the content of the file and not the execution of the file. Instead of display the info of PHP, I got the text of the file as: <?php phpinfo(); ?> Why? Thanks Phong Ho wrote: >I have this problem with PHP that someone might be able to help. > >With CLI, I am able to execute my ....

PHP with Indian PHP Developers
Dear all, If you want to make a PHP web application, or need to <a href="http:// www.virtueinfo.com/php-developers/hire-php-programmers-developers-india.htm">Hire PHP Developer</a>contact a leading <a href="http://www.virtueinfo.com/ php-developers/php-web-development.htm"> PHP Web Development Compnay</ a> <a href="http://www.virtueinfo.com/php-developers/php-web-programming- php-developers-india.htm">Offshore PHP web development India</a> On Thu, 25 Feb 2010 01:37:02 -0800 (PST), Virtue Info wrote: > Dear all, > > > If you want to make a PHP web application, or need to <a href="http:// > www.example.com/php-developers/hire-php-programmers-developers-india.htm">Hire > PHP Developer</a>contact a leading <a href="http://www.example.com/ > php-developers/php-web-development.htm"> PHP Web Development Compnay</ > a> > > ><a href="http://www.example.com/php-developers/php-web-programming- > php-developers-india.htm">Offshore PHP web development India</a> > Third time's the charm? Not exactly a ringing endorsement of the skills you've got available or your testing method reliablity... -- 12. One of my advisors will be an average five-year-old child. Any flaws in my plan that he is able to spot will be corrected before implementation. --Peter Anspach's list of things to do as an ...

PHP Question
Can I do threading with PHP ? better ask this question at another place. On Tue, 01 Jun 2004 17:53:08 GMT, Hot Tamales ! <hot@mexico.gov.org.food> wrote: > > Can I do threading with PHP ? > > -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ but I asked it here; top posting fuck face On Tue, 01 Jun 2004 23:41:34 +0530, sox wrote: > > better ask this question at another place. > > > On Tue, 01 Jun 2004 17:53:08 GMT, Hot Tamales ! <hot@mexico.gov.org.food> > wrote: > >> >> Can I do thread...

Php constants in php.ini
I am trying to set user_agent = PHP_VERSION in php.ini. In my php.ini the instructions say that you can use constants in the php.ini file. The only constants I can get to work, though, are the error level constants like E_ALL, E_ERROR, E_WARNING, etc., ... Is anyone aware of some sort of trick to getting others to work? (I was thinking it would be nice to have the user agent string used by my Php scripts to use PHP_VERSION in the string.) -- ***************************** Chuck Anderson • Boulder, CO http://www.CycleTourist.com Integrity is obvious. The lack of it is common. *****...

Does PHP need the .php extension ?
Hi guys, When I use PHP I give my file the .php extension. I always wondered if it could be an .htm page with a <script> block that the PHP resides in, the same way you would do JavaScript. If you can do it that way are there any benifits to that method ? Take care, Cyrus "Cyrus D." <satan@invalid.org> writes: > Hi guys, > > When I use PHP I give my file the .php extension. I always wondered if it > could be an .htm page with a <script> block that the PHP resides in, the > same way you would do JavaScript. If you can do it that way are the...

PHP Question
I have to know the hiding of the sub url of the url suppose www.mydomain.com/index.php I don't want the sub url.I want only www.mydomain.com for all pages can you give the coding for the concept. It(code) may be either javascript or php or browse enabled, or Apache configuration please....... karthik wrote: to a javascript newsgroupt with a subject line of "PHP question". X-Trace: posting.google.com Had to be :-) > I have to know the hiding of the sub url of the url suppose > www.mydomain.com/index.php Why? Trying to hide something, are we? > I don't want the...

php://memory and php://temp
http://php.net/manual/en/wrappers.php.php per the documentation: php://memory and php://temp are both listed under "Allows Appending" what am I missing / what's the point? They only seem to work with read/write modes such as fopen('php://memory','rw'); closing the handle, or trying to open another handle without closing the first essentially erase the contents... so what's the point of fopen('php://memory','a') ? you'll a) be appending nothing, b) no way to read what you just wrote? sure would be nice if you could $fh = fopen('php://memory', 'w'); fwrite($fh, 'test string'); fclose($fh); $fh = fopen('php://memory', 'r'); $result = fgets($fh,2048); fclose($fh); echo $result; On 10/12/2010 9:44 PM, BKDotCom wrote: > http://php.net/manual/en/wrappers.php.php > per the documentation: php://memory and php://temp are both listed > under "Allows Appending" > > what am I missing / what's the point? > > They only seem to work with read/write modes such as > fopen('php://memory','rw'); > > closing the handle, or trying to open another handle without closing > the first essentially erase the contents... so what's the point of > fopen('php://memory','a') ? > you'll > a) be appending nothing, > b) no way to read what you just wrote? > > sure would be nice if you could > > $fh = ...

about php lang
plz told me that what is the php lang., how does it works and where it used. mani <msb.jod@gmail.com> wrote: > plz told me that what is the php lang., how does it works and where it > used. There is a good explanation at http://lmgtfy.com/?q=php regards Henrik -- The address in the header is only to prevent spam. My real address is: hc3(at)poolhem.se Examples of addresses which go to spammers: root@localhost postmaster@localhost On 16 Jun 2009, mani <msb.jod@gmail.com> wrote: > plz told me that what is the php lang., how does it works and > where it used. Lulz. <http://www.google.com/> -- ~Curtis Anonymous (1984 IOCCC winner): int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\ o, world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);} mani schreef: > plz told me that what is the php lang., how does it works and where it > used. http://en.wikipedia.org/wiki/Php Tip: If you want to learn something about a subject totally new to you, try wikipedia for a reasonable intro. Regards, Erwin Moller -- "There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." -- C.A.R. Hoare ...

PHP Question
For a NON-Technical person how easy is it to learn PHP ? (for website changes - mostly minor changes)I have never done any programming. If any one would be kind enough to let me know I would appreciate it. Thanks Sarah "sarah rosen" <sarahrosen1@yahoo.com> wrote in message news:cee28c30.0401162017.1f82f1c@posting.google.com... > For a NON-Technical person how easy is it to learn PHP ? (for website > changes - mostly minor changes)I have never done any programming. > > If any one would be kind enough to let me know I would appreciate it. > > Thanks > Sara...

PHP Question
Hello every one, I need your help because I have no idea how to do this... how can I get the veg_id into the table veg_type according to the vegetable name chosen in the pick list ? do I have to create another query in test2.php which select the veg_id from the vegetable table ? I would like to no what's best, I mean what's professional? I created those two tables for my test: create table vegetables ( veg_id number(5), veg_name varchar2(30)); insert into vegetables values (1,'carot'); insert into vegetables values (2,'spinach'); insert into...

why does $_SERVER['PHP_SELF'] say /test.php/test.php for test.php?
I have a PHP script at 127.0.0.1/test.php. It's contents are as follows: <?php echo $_SERVER['PHP_SELF']; ?> And it's output isn't test.php, as I'd expect, or /test.php, but rather, /test.php/test.php. Why? And how do I fix it? El 06/10/2010 6:53, yawnmoth escribi�/wrote: > I have a PHP script at 127.0.0.1/test.php. It's contents are as > follows: > > <?php > echo $_SERVER['PHP_SELF']; > ?> > > And it's output isn't test.php, as I'd expect, or /test.php, but > rather, /test.php/test.php. Why? And how do I fix it? What output do you get if you change it to this? <?php echo '[' . $_SERVER['PHP_SELF'] . ']'; ?> What do your other $_SERVER values look like? <?php print_r($_SERVER); ?> -- -- http://alvaro.es - �lvaro G. Vicario - Burgos, Spain -- Mi sitio sobre programaci�n web: http://borrame.com -- Mi web de humor satinado: http://www.demogracia.com -- On 06/10/10 09:30, "�lvaro G. Vicario" wrote: > El 06/10/2010 6:53, yawnmoth escribi�/wrote: >> I have a PHP script at 127.0.0.1/test.php. It's contents are as >> follows: >> >> <?php >> echo $_SERVER['PHP_SELF']; >> ?> >> >> And it's output isn't test.php, as I'd expect, or /test.php, but >> rather, /test.php/test.php. Why? And how do I fix it? > > What output do you get if you change it ...

php
hi all iv extracted a phptimesheet on my system but the webserver is not able to show the documents in html format...i mean..the <?php headers are also visible on the page... can any one help me out with this. linuxadmin wrote: > hi all > > iv extracted a phptimesheet on my system but the webserver is not able > to show the documents in html format...i mean..the <?php headers are > also visible on the page... > > can any one help me out with this. It sounds like a configuration error with your webserver---it would seem that it's not interpreting PHP files...

Web resources about - Question on PHP regular expressions - comp.lang.php

Expression (mathematics) - Wikipedia, the free encyclopedia
In mathematics, an expression is a finite combination of symbols that is well-formed according to rules that depend on the context. Symbols can ...

Arab women artists and their long road to expression
At a London festival, female artists grapple with the issues facing their region and their own identities.

Christie’s Expressions At Trump Event Under Scrutiny
Donald Trump Holds Super Tuesday Election Night Press Conf. In Palm Beach PALM BEACH, FL - MARCH 01: Republican Presidential frontrunner Donald ...

Decoding The Facial Expressions Of The GOP Candidates
Trump's "crooked contemptuous" smile, Rubio's sheepish grin, and Cruz's upper lip of disgust dominated the debate. For tonight's Republican ...

You enjoy freedom of expression only because army guards borders: Delhi HC to Kanhaiya Kumar
The bail granted to Kanhaiya Kumar comes with several conditions, directives to JNU faculty and some serious observations

Bernie Sanders Brought His Finest Facial Expressions to the Democratic Debate
You may not like Bernie Sanders as a presidential candidate, but you’ve gotta admit, this man’s got some pretty expressive peepers. Read more... ...

Crosswords Help You Learn Regular Expressions
Regular expressions might seem arcane, but if you do any kind of software, they are a powerful hacker tool. Obviously, if you are writing software ...

Security, the Greatest Threat to Free Expression?
Like it or not, today we are all, in one way or another, engaged in a battle between perceived security and freedom of expression. And far too ...

'Animal Soul' Book Of Photos: Expression in Cats and Dogs
Intrigued by the facial expressions of dogs and cats, photographer Robert Bahou is compiling a book of his efforts to capture them.

It Turns Out Vanessa Hudgens' Expression of Love Was Highly Illegal
The Federal Government cares more about some old, dead, scratched up rocks in the desert than it cares about Vanessa Hudgens and Austin Butler ...

Resources last updated: 3/23/2016 7:15:53 PM