The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 21, 2019, 12:44:28 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: preg_replace_all function overview info.  (Read 7427 times)
nattsurfaren
Journeyman
***
Offline Offline

Posts: 64


View Profile
« on: December 02, 2008, 09:16:28 AM »

Where can I find a spec for preg_replace_all.
The reason is because I stumbled upon pdf coding that I'm unsertain of what it does.
Code:
$id = $this->xref_table->get_next_free_id();

$cache = Array();
for ($i=0; $i<count($arr); $i++) {
/* check if object is a root field */
if (object_in_array($arr[$i], $root_fields->arr)) {
$fields_holder[] = $i;
}

$old = "/([^0-9])".$arr[$i]->id . "\s" . $arr[$i]->generation . "\sR/";
$new = "_".$id . "_0_R";
preg_replace_all($old, "\\1".$new, $arr);
$cache[$new] = $id . ' 0 R';
$arr[$i]->id = $id;
$arr[$i]->generation = 0;
$id++;
}


preg_replace_all($old, "\\1".$new, $arr);
Search for $old
and replace with "\\1".$new.
I think it loops through $arr and replaces within but I'm not 100%.
I'm also unsertain what the regex does.

Appreciate your help.
/Natt
Logged
nattsurfaren
Journeyman
***
Offline Offline

Posts: 64


View Profile
« Reply #1 on: December 02, 2008, 09:31:22 AM »

I think I know what the regex means now.
Code:
$old = "/([^0-9])".$arr[$i]->id . "\s" . $arr[$i]->generation . "\sR/";
Finds strings like '5 0 R'
5 0 without R is replaced in all places in the array with "\\1"."_".$id . "_0_R";

Is this correct?
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #2 on: December 02, 2008, 11:15:45 AM »

preg_replace replaces all by default: http://us3.php.net/manual/en/function.preg-replace.php

You can place arrays in any of the 3 positions of that function, but it gets weird how it behaves if you're not careful.

  • single value in parm 1, 2, 3: replace occurrences of (1) with (2) on input (3)
  • Arr as parm 1, single value in parms 2 & 3: For each (1) replace with (2) on (3)
  • Single value as parm 1, arr as parm 2, single as parm 3: Same behavior as singe value in 1,2,3
  • Array as parm 1 & 2, single value 3: for each (1) replace with parallel (2) on input value(3)
  • Array as parms 1,2,3: For each (1) replace with parallel (2) on parallel (3). This one gets really weird it the arrays are not exactly the same length.


Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
ButanZEr
n00b
*
Offline Offline

Posts: 1


View Profile
« Reply #3 on: June 08, 2009, 12:55:36 AM »

              I think I might use the codes that i got in this discussion.,

________________
Butaun City | alaminos city
« Last Edit: June 08, 2009, 06:22:25 AM by vsloathe » Logged

No links in signatures please
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #4 on: June 08, 2009, 11:08:09 AM »

lol V

Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #5 on: June 08, 2009, 02:44:02 PM »

 ROFLMAO
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #6 on: June 09, 2009, 10:24:37 AM »

We should have fun with one of these guys some time. If they're too incompetent to remove forums like this one from their lists, we should make sure their sites rank for some terms that raise the ire of certain federal agencies.

 ROFLMAO
Logged

hai
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!