Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 5th, 2004, 03:10 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default Regular Expression problem

I have the following two lines (seperated by a CR/LF) that I am trying to combine into one string.



Note: The "_N_" prefix has been stripped, and the "_" in "_WPD" and "_SPF" has been switched ot a ".".

I think I should be able to do this with a Regualr expression, but I don't even know where to beging.
Old May 13th, 2004, 06:59 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts

Look at preg_replace(). The expression might be a bit tricky, so you'll probably have to attack it bit by bit. I suggest starting small, just try to solve mini problems. For example, just write an expression that matches the first line and extracts the parts you want. Then do the same for the second line. Then figure out how to combine your patterns into a single pattern, or keep them separated and assemble your final string using the matches arrays of your individual preg_match() calls.

Make sense?

Take care,

Old May 14th, 2004, 07:43 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts

Why not have a go with:

$yourstring_minus_the_silly_linebreak = str_replace("\r\n", $yourstring);

Or failing that, str_replace(chr(13).chr(10),... Using the actual ASCII values of Cr&Lf, concatenated together.

Hope it works

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expression repeat problem Indo77 ASP.NET 2.0 Basics 1 May 28th, 2008 06:45 AM
Regular expression problem keyvanjan ASP.NET 2.0 Basics 0 May 28th, 2007 12:19 PM
Regular Expression escaping problem! nerssi Java Basics 1 June 14th, 2006 07:16 PM
regular expression problem muki XSLT 2 January 11th, 2006 06:04 AM
Regular expression problem ghalebro PHP How-To 1 August 24th, 2004 08:10 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.