[PHP] Regular Expression Problem and PHP 4 (urgent)
Here is the problem: I'm retrieving a page of data from another process using PHP4 on Solaris 2.51 This data is placed in an array by line and simply returned to the browser after formatting. A sample line may look something like this: blah blah blah blah blah blah blah blah blah I think I need to use eregi_replace to make the line look like this: blah blah blah blah blah blah blah blah blah when it is returned to the browser. Thanks in advance Ross -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Re: Regular Expression Problem and PHP 4 (urgent)
Actually I didn't pose my question correctly. I also needed to grep out the "Link" for use in JS during the process. I wrapped this in a class file and here is the entry that I ended up with. Thanks for the assist though... == function getPL($plric) { //variable set to add at the end of the RIC if it's a stock not a page $temp = "B2"; //find out if it's a stock by query for the period in the RIC if (eregi("\.", $plric)) { //add B2 if it's a stock $plric = $plric + $temp; } //the data comes out of the server pipe delimited $pages = split("\|",`/mdsweb/cgi-bin/Snap_Pages -s 000.000.000.00 -p 34927 -r $plric`); $a=0; while ($pages[$a] != "") { $pages[$a] = htmlentities($pages[$a]); //replace spaces with $pages[$a] = str_replace(" ", " ", $pages[$a]); //find the left angle brackets $a1 = spliti("<", $pages[$a]); $b=0; while ($a1[$b] != "") { //if the resulting data has a right angle bracket if (eregi(">", $a1[$b])) { $a2 = spliti(">", $a1[$b]); if (eregi("\.", $a2[0])) { echo "<"; echo $a2[0]; //put back the right angle bracket in the link echo ">"; $c=1; //echo the link itself while ($a2[$c]) { echo $a2[$c]; $c++; } } else { echo ""; echo $a2[0]; echo ""; $c=1; while ($a2[$c]) { echo $a2[$c]; $c++; } } } else { echo $a1[$b]; } $b++; } echo ""; $a++; } } "Richard Lynch" <[EMAIL PROTECTED]> wrote in message 00a001c1253f$53fad780$6401a8c0@Lynchux100">news:00a001c1253f$53fad780$6401a8c0@Lynchux100... > > blah blah blah blah blah blah blah blah blah > > > > I think I need to use eregi_replace to make the line look like this: > > blah blah blah blah blah blah blah blah blah > href='#'> > > Depending on how accurately you have stated the problem, this may work: > > $text = 'blah blah blah blah blah blah blah blah blah '; > $text = str_replace('<', " $text = str_replace('>', ">", $text); > $text = str_replace('XX', '>', $text); > > -- > WARNING [EMAIL PROTECTED] address is an endangered species -- Use > [EMAIL PROTECTED] > Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm > Volunteer a little time: http://chatmusic.com/volunteer.htm > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Regular Expression Problem and PHP 4 (urgent) --- continued
Well my first solution didn't really work the way I needed it too so here goes again... Data returned from server process looks like following... Header datadatadatadata[link]datadatadata{link}data[link] datadata{link}data[link]datadatadata{link}data[link] datadatadatadata[link]datadatadata{link}data[link] Closer I need to grep the values between [] and {} to turn them into a links. (BTW I need to retain the values for use in JS) Any suggestions? Thanks, Ross -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Regular Expression Problem and PHP 4 (urgent) --- continued
Andrey, Thanks for the time that you put into this! After some tweaking (for my scripts) I got this working nicely, and learned a thing or two about PREG also. Ross Nielsen [EMAIL PROTECTED] "Andrey Hristov" <[EMAIL PROTECTED]> wrote in message 02d801c12f2e$c1a60a90$0b01a8c0@ANDreY">news:02d801c12f2e$c1a60a90$0b01a8c0@ANDreY... > Some time spent to try but now i think it works: > > echo ""; > $a='datadatadatadata[link1]datadatadata{link2}data[link3]'; > // $a='datadata{link1}data[link2]datadatadata{link3}data[link4]'; > $pattern='/((\[)|\{)(.+?)(?(2)\]|\})/'; > echo $a."\n"; > echo $pattern."\n"; > preg_match_all($pattern,$a,$matches,PREG_MATCH_ORDER); > var_dump($matches); > ?> > > Produces : > datadatadatadata[link1]datadatadata{link2}data[link3] > /(\[)|\{(.+?)(?(1)\]|\})/ > array(3) { > [0]=> > array(3) { > [0]=> > string(1) "[" > [1]=> > string(7) "{link2}" > [2]=> > string(1) "[" > } > [1]=> > array(3) { > [0]=> > string(1) "[" > [1]=> > string(0) "" > [2]=> > string(1) "[" > } > [2]=> > array(1) { > [0]=> > string(5) "link2" > } > } > > Also works with the commented string. > Explanation : Looking for more than one using preg_match_all. Matching for [ or {, [ is in () because at the end we test if we found > [ so we look for ] otherwise { is found so we look for matching }. (?(1) true|false) is 1 as a backreference is set so we found [. > > Hope this will help you. > > Andrey Hristov > IcyGEN Corporation > http://www.icygen.com > 99% > > > - Original Message - > From: "Ross Nielsen" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Monday, August 27, 2001 9:42 PM > Subject: [PHP] Regular Expression Problem and PHP 4 (urgent) --- continued > > > > Well my first solution didn't really work the way I needed it too so here > > goes again... > > > > Data returned from server process looks like following... > > > > Header > > datadatadatadata[link]datadatadata{link}data[link] > > datadata{link}data[link]datadatadata{link}data[link] > > datadatadatadata[link]datadatadata{link}data[link] > > Closer > > > > I need to grep the values between [] and {} to turn them into a links. > > (BTW I need to retain the values for use in JS) > > Any suggestions? > > > > Thanks, > > Ross > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]