Jump to content

lwc

Members
  • Posts

    30
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

lwc's Achievements

Member

Member (2/5)

0

Reputation

  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!
  5. Thanks! So in my case it would be: $array = array(5 => "001", 2 => "001001", 1 => "001001001", 9 => "002", 7 => "002001"); foreach ($array as $key => $val) { $count = strlen($val) / 3; for ($x = 0; $x < $count; $x++) { echo "<ul class=\"advance level\">"; if ($x == $count-1) echo "<li>"; } echo "$key"; for ($x = 0; $x < $count; $x++) { if (!$x) echo "</li>"; echo "</ul>"; } }
  6. $array = array(5 => "001", 2 => "001001", 1 => "001001001", 9 => "002", 7 => "002001"); Each 3 digits mean a new level or sub level (e.g. XXX, XXXYYY, XXXYYYZZZ, etc.). What I want is to have this printed: <ul class="level"> <li>5</li> <ul class="level"> <li>2</li> <ul class="level"> <li>1</li> </ul> </ul> <li>2 <ul class="level"> <li>7</il> </ul> </ul> As <ul class="level"> adds another visual level, it should look something like: *5 **2 ***1 *9 **7 What do you think is the easier way to do it? Thanks!
  7. I like this too. But can you deal with "<" and ">" too?
  8. Okay, on further thinking I guess "p" doesn't even need this because Unicode characters can't be used in HTML tags anyway. As for "b", fataqui's simple (relatively...) approach seems to work great for me. I'll continue the debate there.
  9. Turns out there's still one problem. Both "b" (when not in Unicode) and "p" (when in Unicode) also match "<match", "match>", "<match" and "match>". Is there a way to make PHP (both in and not in Unicode) realize a < or > (and their equivalents) next to the match means the match is not a whole word? Thanks!
  10. You're a genius! I've tried messing with \p{L} by byself before, but the real challenge was to surround it with things that would make work like \b (both for the start and for the end) - and that's what you managed to do. Any chance you can explain how come "?<!" and "?!" do the trick?
  11. LC_COLLATE=C;LC_CTYPE=Hebrew_Israel.1255;LC_MONETARY=C;LC_NUMERIC=C;LC_TIME=C
  12. That line makes no difference. I've tried this on v5.2.5. Tell me which command tells me my locale.
  13. Why do you need regexp for this? Just use http://php.net/strpos And remember the opposite of "===" is "!==". Of course, if you just do what you want directly, it would also match "http://www.phishing.com/integrateditsystems.co.uk/trickedyou/".
  14. And this is what I get when I copy and paste your code: Es ist heiß. Wie heißen Sie? Es ist heiß. Wie heißen Sie?
×
×
  • 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.