Jump to content

lwc

Members
  • Posts

    30
  • Joined

  • Last visited

    Never

Everything posted by lwc

  1. The following code is relatively short, but censors any HTML tags inside the XML: function object2array($object) // from php.net { $return = NULL; if(is_array($object)) { foreach($object as $key => $value) $return[$key] = object2array($value); } else { $var = get_object_vars($object); if($var) { foreach($var as $key => $value) $return[$key] = ($key && !$value) ? NULL : object2array($value); } else return $object; } return $return; } $bla=simplexml_load_file($xml_file); $bla=object2array($bla); This one keeps HTML but turns everything into one giant string: $bla=$bla->asXML(); So how can I easily preserve HTML? But better yet, can I somehow just tell PHP which tags to convert? For example, only <this> and <that> in: <this> <that>Text <foo>and</foo> test and <whatever>something</whatever>.</that> </this> thus creating: Array ( [this] => Array [0] => Array ( [that] => Text <foo>and</foo> test and <whatever>something</whatever>. ) }
  2. If one wants to modify internal code segments before modifying external ones, there's a proof of concept of it in Example #3 of preg_replace_callback(). However, it only deals with just one tag. Can you think of a way to expand it to multiple tags? Also, not with BB code but actual <custom code>. For example, $input = "Hi, this is <custom_code1>just <custom_code2>my</custom_code2> <custom_code3>example</custom_code3></custom_code1>. How can it <custom_code4>get <custom_code5>done</custom_code5></custom_code4>?"; Another function does different things for what's inside each of the custom codes. Basically codes 2 & 3 need to run before code 1 can, and code 4 needs to run before code 5 can. Thanks!
  3. Again, I also want to replace things before/after the so called bbcode. This means part of the replacements would be outside of tags and not within them. If you have any way to reach my desired result text, please show how, whether it's regex or not.
  4. <?php function dosomething($string, $else = '') { if (empty($else)) $string = "<b>$string</b>"; else $string = "<i>$string</i>"; return $string; } $input = "Some words. [code]some code. More words. . Other words."; $codetag = array('\ [code\]', '\[quote\]'); $codetag_rev = array('\[\/code\]', '\[\/quote\]'); for ($i = 0; $i < count($codetag); $i++) $codetag_array[] = "/([\s\S]*$codetag[$i])([\s\S]+)($codetag_rev[$i])([\s\S]*)/e"; $input_new = preg_replace($codetag_array, 'dosomething("$1") . dosomething("$2","else") .dosomething("$3") . dosomething("$4")', $input); echo "$input\n<hr>\n$input_new"; // This becomes a huge mess and $2 doesn't get saved from being bold echo "<hr><hr>"; // It does work fine if I only try it on one tag $input_new = preg_replace($codetag_array[0], 'dosomething("$1") . dosomething("$2","else") .dosomething("$3") . dosomething("$4")', $input); echo "$input\n<hr>\n$input_new"; // $2 is indeed saved from turning bold ?> [/code] So my only question is - how do I do this for multiple tags? Or, if you want, you can simply ignore everything until now and just tell me how do I turn $input into: // Output: <b>Some words. [code]</b><i>some code.</i> <b> More words. . Other words.</b>; [/code] Thanks!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.