Jump to content

Special characters in wireArray()

Recommended Posts

I want to have filters with month names in german. I fetch them from date-fields with strftime('%B', $timestamp);
But i'm not able to add them correctly to a wireArray()

What's the right way to do that?

  $ms = wireArray();
  $m1 = strftime('%B', 1579643232); // Januar
  $m2 = strftime('%B', 1583107200);	// März


  foreach($ms as $name) {
	  echo "$name ";
		// result: Januar M�rz


Link to post
Share on other sites

i bypassed it with a static helper-array and it works.
would be nice to know how to do this without a helper array

$mNames = array("zero", "Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");
$ms = wireArray();
  $m1 = date('n', 1579643232); // 1
  $m2 = date('n', 1583107200); // 3


  foreach($ms as $name) {
	  echo "$mNames[name] ";
  // result: Januar März


Edited by ngrmm
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Moebius
      I need to sort results by title ascending, and title includes special characters (croatian letters).
      The problem is that results are sorted but not 100% correct:
      $authors = $pages->find("template=author,sort=title"); Cavali Cavilon Čavlović Cesare ... You see intruder (bolded), it looks like sort engine treats letters C and Č as same ones.
      I'm not sure that this is Processwire related, but maybe API has solution for this kind of behavior?
      I have UTF-8 page content type .
    • By celfred
      Still in my 'teaching game'. Here's my problem : I 'find' all players with a request like

      $allPlayers = $pages->find("template=player"); [/code Then, I limit to players belonging to the team of the logged in player with [code] $teamPlayers = $allPlayers->find("team=$loggedPlayer->team");
      No problem so far. But my scoreboards rely on either :


      to find the logged player's position in the charts.
      On the 'global' newboard with scoreboards based upon $allPlayers, everything works as expected.
      BUT on my 'team' newsboard, even though I'm using $teamPlayers, the returned indexes are based upon $allPlayers. Am I clear ? In other words, I have a total of 125 players, and my logged player is 61 out of 125 regarding the number of places he freed. But in his particular team of 25 players, he sould be 15 whereas he's still 61
      I'd like to reset my indexes (and start back from 0), but I can't find my way out of this...
      If someone has a hint to help, I'd appreciate.
      I have a second part in my worry : I had a way around it by simply making another 'raw' request :

      $teamPlayers = $pages->find("team=$loggedPlayer->team");
      Then my team indexes were right, but I faced another issue : Reordering my wirearray according to the scoreboard I want usually worked fine (simple sort() based upon an integer field, for example, player's coins, player's karma...) and indexes were updated BUT resorting with places.count ('places' field is a pageArray) doesn't update the indexes returned by getItemKey and my logged player is always at the position he was when I first did my initial $pages->find() query  
      So my way around found its limit and that's why I'm posting here, after struggling with this for a couple of hours...
      Thanks in advance for the help. 
    • By SwimToWin
      While ProcessWire and WireArray does not have support for array_chunk, there is a simple way to achieve this.
      With array_chunk() you can easily add DIVs to a foreach loop, without having to set up counters when using general PHP (hat-tip to Laurance over at StackOverflow). The idea in a ProcessWire context is to use array_chunk() to split an array into chunks - and use eq() when looping page results.
      Simple example that will split a WireArray into three columns. Before we begin, you should know the array_chunk syntax: array_chunk($array, $chunk_size, $preserve_keys=true|false).
      <?php $p = $pages->get('/news')->children('limit=15, template=article, sort=-sort'); ?> <div class="row"> <?php foreach (array_chunk(range(0,14),5) as $chunk): ?> <div class="col"> <?php foreach ($chunk as $i): ?> <h5><a href="<?=$p->eq($i)->url?>"><?=$p->eq($i)->title?></a></h5> <?php endforeach; ?> </div> <?php endforeach; ?> </div> A more realistic example:
      <?php $p = $pages->get('/news'); $pp = $p->children('limit=15, template=article, sort=-sort'); ?> <h2><a href="<?=$p->url?>"><?=$p->title?></a></h2> <div class="row"> <?php foreach (array_chunk(range(0,14),5) as $chunk): ?> <div class="col"> <?php foreach ($chunk as $i): ?> <h5> <a href="<?=$pp->eq($i)->url?>"><?=$pp->eq($i)->title?></a> </h5> <?php endforeach; ?> </div> <?php endforeach; ?> </div>
    • By kongondo
      In a module-context, as we know, stuff like single file or image fields return 'arrays', i.e. become iterable. This means that directly using WireArray::Iterable() to check whether a field is iterable can be misleading. Other than to temporarily set a page's output formatting to true (still within a module context), checking iterability of a field on the page, then reverting the page's output formatting to false after the check, is there another/a better way to achieve the same feat? Thanks.
    • By pwFoo
      I build a new module and try to convert data into WireArray to get the PW API benefits (find('selector'), get('selector'), ...).
      Some code to my tests...
      Define a custom WireArray class
      class CustomWireArray extends WireArray { public $toStringString = ''; public function __toString() { return $this->toStringString; } public function __get($key) { return $this->$key; } public function __set($key, $value) { $this->$key = $value; } } Create a new CustomWireArray
      $customWireArray = new customWireArray(); Create a new array item
      $item = new customWireArray(); // set properties to $item... $customWireArray->add($item); // add to the customWireArray So far it works fine. No problem to find() / get() properties from the $customWireArray, but I need sub-items 
      Tested it with a sub-customWireArray and also a simple stdClass, but it won't work with PW find() / get().
      Is there a way to get sub-properties work with something like that?
      $result = $customWireArray->find('property.subfield=MyValue');
  • Create New...