Jump to content

Search the Community

Showing results for tags 'php'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to ProcessWire
    • News & Announcements
    • Showcase
    • Wishlist & Roadmap
  • Community Support
    • Getting Started
    • Tutorials
    • FAQs
    • General Support
    • API & Templates
    • Modules/Plugins
    • Themes and Profiles
    • Multi-Language Support
    • Security
    • Jobs
  • Off Topic
    • Pub
    • Dev Talk

Product Groups

  • Form Builder
  • ProFields
  • ProCache
  • ProMailer
  • Login Register Pro
  • ProDrafts
  • ListerPro
  • ProDevTools
  • Likes
  • Custom Development

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

  1. Hello, i am trying to solve one issue from 2 days but no luck. i am developing one project in PW and its working perfect as always but issue is in footer file i am using one JS file as bellow <script src="<?php echo $config->urls->templates?>assets/js/script.js"></script> file load but script.js use few other files as bellow include('js/jquery.easing.1.3.js'); these files are not loading , i have copied the JS folder in root and Home page start working but when i goto sub pages JS again stop working. issue is with JS path. how to fix that ? Thanks
  2. Hi there, Here's my problem which lets me... with a big ? in the head I have this simple piece of code : if ($page->name === 'blog' OR $page->name === 'documentation') { $class = 'on'; } else { $class = ''; } It triggers the error : Parse Error: syntax error, unexpected '$page' (T_VARIABLE) (line 114 of /home/celfred/PlanetAlert/site/templates/head.inc) This error message was shown because you are logged in as a Superuser. Error has been logged. If I get rid of the OR statement, it works fine. If I choose the right part of the OR statement alone, it works fine. If I type || instead of OR (what I did at first), it throws the error. And here's the best part : If I copy/paste the || from another IF statement that works fine in my site, it WORKS !! This is becoming a nightmare. I can't type a regular OR statement in my PHP code. I have to copy/paste the characters and it works. If anyone has a clue to help me on that, I would really appreciate because as I often say, being no professional coder, I kind of take A LOT of time on programming issues, but here, this weird behavior is over my head. I feel desperate when I stumble upon such basic parts of code Thanks in advance ! PS : I've tried to dig into my PHP config that would have changed since some kind of upgrade, but with no luck... I've looked at my file encoding (utf8)... Well, I'm stuck ! EDIT : Just to illustrate more : Copy/paste from another file that works : if ($page->name == 'blog' || $page->name == 'documentation') { If I retype the || operator and save and reload on my localhost : tada! Error !!!
  3. I have a template called "activity" with two pagetable fields. Fields: activity_create_cast activity_create_date activity_create_cast: uses "cast" template for creating castpages. the cast template contains a pagefield called select_multi_dates. activity_create_date: uses "date" template for creating datepages. the date template contains a pagefield called select_activity. Now what i want is create a cast with activity_create_cast and I want that the selection of the select_multi_dates pagefield should be the pages wich i created before with the activity_create_date. How can I achieve this under the select_multi_dates pagefield with a PHP-Selector? I know its complicated PHP-Selector. Hope you can help me. Thanks for your attention. Nukro
  4. Hello Processwire Community Lets say I have a Multi-User-System where I can create/update as "normal" user new events, dates, multimediapages, imagepages etc.... As Admin I can create organisers(owners) and assign them respectively to specific users. Module for creating/updating pages: Fredi - Friendly Frontend Editor Scenario: Add new Imagepage under Multimedia > Images Important Fields select_organiser(FieldtypePage)(btw. this field is assigned to the user template) PHP-Selector for "select_organiser" if(wire('user')->isSuperuser()){ return $pages->find("template=organiser"); } else{ return $pages->find("template=organiser, id=".wire('user')->select_organiser); } Templates image-index(is assigned to Image-Page) -> Fields: only title - > images-index.php Only show the image pages which has the same organiser like the current user. <?php $out .="<h3>$title verwalten</h3> <div class='span11'> <div class='btn-pos-1 add'>" .$fredi->setText("<i class='fa fa-plus'></i> Bild erfassen")->hideTabs("children|delete|settings")->addPage("image", "title|select_organiser", $pages->get(1153)). "</div> <table id='example' class='row-border' cellspacing='0' width='100%'> <thead> <tr> <th>ID</th> <th>Bildname</th> <th>Bild</th> <th>Beschreibung</th> <th>Veranstalter</th> <th>aktualisiert</th> <th></th> <th></th> </tr> </thead> <tbody>"; if($user->isSuperuser()){ $images = $pages->find("template=image"); } else{ $images = $pages->find("template=image, select_organiser=$user->select_organiser"); } foreach ($images as $i_item) { if($i_item->image){ $thumb = $i_item->image->size(50, 50); } $out .= "<tr> <td>{$i_item->id}</td> <td>{$i_item->title}</td> <td><a class='large_img' href='{$i_item->image->url}' ><img src='{$thumb->url}' /></a></td> <td>{$i_item->image_body}</td> <td>{$i_item->select_organiser->title}</td> <td>".date('Y-m-d', $i_item->modified)."</td> <td><a href='{$i_item->url}'><i class='fa fa-eye'></i></td> <td>".$fredi->setText("<i class='fa fa-pencil'></i>")->renderAll($i_item)."</td> </tr>"; } $out .= " </tbody> </table> </div>"; images(is assinged to children-items of Image-Page) -> Fields: title, image, image_body, select_organiser -> images.php At the beginnnig of the template it checks if the select_organiser of the current user is the same as the select_organiser of the current image page. <?php if($user->select_organiser == $page->select_organiser || $user->isSuperuser()){ $out .= "<h3>{$page->parent->title} Details</h3> <div class='span8'> <table class='detail-view table table-striped table-condensed'>"; $out .= "<tr class='odd'><th>ID</th><td>{$page->id}</td></tr>"; //get all fields: $all_fields = $page->fields; foreach($all_fields as $field){ if($field->type == "FieldtypeImage"){ $out .= "<tr class='odd'><th>{$field->label}</th><td>{$page->get($field->name)->url}</td></tr>"; } else if($field->type == "FieldtypePage"){ $out .= "<tr class='odd'><th>{$field->label}</th><td>{$page->get($field->name)->title}</td></tr>"; } else{ $out .= "<tr class='odd'><th>{$field->label}</th><td>{$page->get($field->name)}</td></tr>"; } } $out .= "<tr class='odd'><th>erstellt</th><td>".date("Y-m-d H:i:s", $page->created)."</td></tr> <tr class='even'><th>aktualisiert</th><td>".date("Y-m-d H:i:s", $page->modified)."</td></tr> </table> </div> <div class='span3'> <div id='sidebar'> <ul class='well nav nav-list' id='yw1'> <li class='nav-header nav-header'>Aktionen</li> <li><a href='{$page->parent->url}'><i class='fa fa-list'></i> Bilder auflisten</a></li> <li>".$fredi->setText("<i class='fa fa-pencil'></i> Bild bearbeiten")->renderAll($page)."</li> </ul> <br /> </div> </div>"; } else{ $session->redirect($error404->url); } The Problem of this System is that the user still can access to image-pages in the backend that dont have the same organiser. Its only view protected. So finally my Question: Can i specifiy a PHP-Selector for the editable pages for the Page Edit Per User Module. Like: return $pages->find("template=images, id=".wire('user')->select_organiser); So that the user can edit the image - pages which has the same organiser like him? Pagetree Structure and some screenshots of the interfaces for visualization: Pagetree Structure: Home(Login-Page) - Dashboard(Intro-Page) -- Events(visible for superuser and user with role: company) -- Agenda/Dates(visible for superuser and user with role: company) -- Multimedia(visible for superuser and user with role: company) --- Images(template: image-index) ---- example-img.jpg(template: image) ... --- Videos -- Profile(visible for superuser and user with role: company) -- Organisers(Only visible for Superuser) --- Organiser-Profiles ---- XYZ AG ... --- Adresses --- Locations -- Settings(Only visible for Superuser) -- Logout Image - Overview Page Image - Detail Page PS: Sorry for the long post
  5. Hello Processwire Community Lets say i have a pagefield called select_organiser. The select_organiser pagefield is assigned to the user template and to the location template. Every User can create a location where he can set a organiser with the select_organiser pagefield. The Superuser can also create locations and he can assign a organisation to a user. No what i want is that the pagefield should check if the current user is a superuser, when yes he get a selection of all organiser pages. But when the current user is not a superuser he should get only a selection/select of the organiser that the Superuser has assigned to him. for example: organiser pages: organiser-example-1 organiser-example-2 organiser-example-3 organiser-example-4 ... users: test-user-1 test-user-2 ... Lets say I am the Superuser and i assign organiser-example-1 to the user test-user-1. Use Case: Create Location as Superuser I have a select with the selection: (organiser-example-1, organiser-example-2, organiser-example-3, organiser-example-4 ...) Use Case: Create Location as test-user-1 I have a select only with the selection: (organiser-example-1). This means I can only create Locations with the organiser: organsier-example-1. I hope you understand what i want to say/ask.
  6. I'm trying to achieve a specific selection for a pagefield for specific users. My pagefield should detect: If the current user is a superuser return all address-pages and when it's not a superuser, return all address-pages which the current user has created. It works fine for the superuser but i have no selection in all the other users. if(wire('user')->isSuperuser()){ return $pages->find("template=address"); } else{ return $pages->find("template=address, created_users_id=wire('user')->id"); }
  7. This has probably been asked a million times, but I can't seem to find an answer. I have always just used a php script to process the emails and was excited that I could pass in an email address from a page to the script using $page. However, this does throw a 403. I was told that I shouldnt be doing it this way, but I was wondering how do you all go about handling emails? I was going to use the same page template, but I need the option of changing out the to email address dynamically.
  8. Hi, while trying to solve image upload problems (https://processwire.com/talk/topic/7749-max-image-dimensions-not-a-recognized-image-bug/) i had a look at the php error.log. There are several rather similar warnings there i understand (s. http://php.net/manual/en/security.intro.php) but not sure to evaluate them in conjunction with PW. Something like: [Mon Sep 14 13:34:14 2015] [warn] [client 79.193.219.101] mod_fcgid: stderr: in Unknown on line 0, referer: [xxx] [Mon Sep 14 14:19:47 2015] [warn] [client 79.205.24.246] mod_fcgid: stderr: PHP Warning: Adding option (Name: 'magic_quotes_gpc' Value: '0') (16, 1) failed! [Mon Sep 14 14:19:47 2015] [warn] [client 79.205.24.246] mod_fcgid: stderr: PHP Warning: Adding option (Name: 'magic_quotes_sybase' Value: '0') (19, 1) failed! [Mon Sep 14 14:19:47 2015] [warn] [client 79.205.24.246] mod_fcgid: stderr: PHP Warning: Adding option (Name: 'register_globals' Value: '0') (16, 1) failed! Setup: PHP 5.4.45-0+deb7u130, mysql 5.5.44-0+deb7u1-log, PW 2.6.1stable I do not experience misbehavior so far while using PW (except this image upload one), but i am curious if this could lead to any problems soon. Thx.
  9. How do I make a folder writeable by PHP? Modules won't load bc one of my directories is not writable in php
  10. Hi folks, I am using the PageField to find selectable pages and I'm using the 'custom PHP code' field to find my pages. However, the following isn't bringing back any pages: $pages->find('parent=/tags/' . $page->parent->name . '/'); I have tested this code on the page template, and it returns the correct pages but entering this into the custom PHP field returns an empty dropdown field. Any thoughts?
  11. Hi, Starting to see alot more errors running PW on php 5.3.3 mainly to do with modules. I am looking to update my VPS soon and was wondering if there was a recommended version e.g. php 5.3.x, 5.4.x, 5.5.x etc Thanks
  12. Hi. I am no PHP expert and have mostly done WordPress development during the last many years, so I am more used to the WordPress codebase than anything else. I have learned that it is good practice to escape your output with different WordPress functions, such as esc_attr, esc_url, esc_html etc. There is a list of functions here: https://codex.wordpress.org/Data_Validation Here is an example, taken from this tutorial: http://code.tutsplus.com/tutorials/data-sanitization-and-validation-with-wordpress--wp-25536 <h1> <?php echo esc_html($title); ?> </h1> I am aware that there are some sanitation functions in ProcessWire, but I have not seen any for this kind of output. Nor have I found any articles/posts about this kind of practice for ProcessWire. The $sanitizer seems to be more specific used for form input data. However, I assume that this is something one should consider in any PHP environment and not only in WordPress? Am I right? I am simply posting this question here, because I am a bit unsure and would love to here what other PHP developers here think about this and what is best to do in the ProcessWire environment. Looking forward to any feedback or input on this subject.
  13. Inspired by Soma's Colorpicker module I'm trying to implement some custom styles for links, backgrounds etc. Martijn said it was possible to add a php file with css in it and echo out the variables in that. I've tried but can't seem to get it going. I've added a custom_styles.php file outside of templates because I believe you cannot have PHP scripts running in there and I've added <?php header("Content-type: text/css"); ?> to the top of the file as advised by Martijn but none of the variables are getting parsed. Has anyone got anything similar working. Currently I'm using Diogo's suggestion of inline styles in the head tags but it just feels a bit wrong (but it is working)
  14. Hi, is there a posibility to check from what site / url user entered your site in php or js ? example... i have a baner on some other site, user clicks it and he is redirected to my site. Is there a way to tell from what site he was redirected from?
  15. Hi guys ! First real project with ProcessWire, and I can say I adopted the platform. It's incredibly fun to work with ! I'm currently making a Google Maps interface, in which I can add branch offices in the backend as pages. Each pages have data : title, latitude longitude etc. and compare it with the user geoloc or a geocoded address. At first, I fetch the childrens ID, latitude and longitude, json_encode them in an array. Then, I find the 3 nearest offices and play with data until I need to get the rest of the data matching the IDs, so I can show detailed profiles of the 3 nearest offices. I'm currently debugging with static data, and I get a 500 internal server error on MAMP... but I don't know, it seems my setup is not showing PHP errors properly. Here is my Javascript function (executed on dom ready elsewhere) : File main.js : function fetchOfficeData() { $.ajax({ url: 'http://127.0.0.1:8888/site/ajax/fetchoffice.php', type: "POST", dataType:'json', data: ({id: 1013}), success: function(data){ console.log(data); } }); } File fetchoffice.php : //Format to fetch the office with the ID $sel_id = 'id=' . (string)$_POST[id]; $result = $page->child($sel_id)->title; echo json_encode($result); But I get an error and I suspect it's because I cannot use selectors in my AJAX page because it's not in my template. I'm able to output $sel_id, or anything else for that matter, but using $page->child... doesn't work. Is it possible to put this code inside my template so the selectors work ? Another solution could be to fetch all the data of all the offices and put them in the json_encode array at the beginning... there will be 30 offices max... but I don't feel like it's the right thing to do. Thank you very much in advance
  16. Need some help. Following works as expected foreach ($page->children as $member) { $key = $member->siblings->getItemKey($member)+1; if ($member == $member->siblings->last()) $rowend = "</div>\n"; elseif ($key%3 == 0) $rowend = "</div><div class=\"row\">\n"; else $rowend = ''; } ternary operator should do the same but brings different result. What is wrong? Cannot see it. foreach ($page->children as $member) { $key = $member->siblings->getItemKey($member)+1; $rowend = ($member == $member->siblings->last())?"</div>\n":($key%3 == 0)?"</div><div class=\"row\">\n":''; }
  17. During module development I've recognized a strange behaviour. Logfile entries in errors.txt and messages.txt are always created twice. This happened on different servers in different environments with different modules. I tested it with this small module: <?php class Debug extends WireData implements Module { public function init() { $this->message(microtime(),Notice::logOnly); // same with $this->error() } } /*log file entries: * 2014-11-07 05:52:14 admin [...]/admin/module/ 0.43575100 1415335934 * 2014-11-07 05:52:14 admin [...]/admin/module/ 0.43575100 1415335934 */ whereas only a simple entry is generated when I provoke an error an catch it to log with exception handling. <?php class Debug extends WireData implements Module { public function init() { try { foo($bar); } catch(Exception $e) { $this->error($e->getMessage(), Notice::log); } } } /*log file entry: * 2014-11-07 12:45:19 admin [...]/admin/module/ Error: Call to undefined function foo() (line 16 of [...]/site/modules/Debug.module) */ Happened this before anywhere? Any Experiences with that? Any Ideas? Couldn't find out the reason for that!
  18. Hi all, again this a more or less PHP-related question: I'm trying to reuse renderNav from the blog.inc file as found in the blog profile. The function accepts parameters: function renderNav($headline, $items, $currentURL = '', $mobile = true) The comment sections says: @param array|PageArray $items May be an array of Page objects or array of ($url => $label) Taken as it is the function outputs the title of the page objects in $items which works fine BUT I would like to output it a different field value ($page->client instead of $page->title in my case). This is where I am stuck with my limited PHP skills. How can I make the function output another field value than $page->title? How would I "put together" an array that contains this field values so that I can assign it as key => value pairs to $items? Thanks
  19. Hi all, I'm trying to adapt the blog profile to my needs. In my template blog-list.php I have the following: $content = renderPosts("limit=10", true); which populates $content in main.php. renderPosts() I have taken as it is from blog.inc in the blog profile: /** * Given a PageArray of blog entries generate and return the output. * * @param PageArray|Page $posts The entries to generate output for * @param bool $small Set to true if you want summarized versions (default = false) * @return string The generated output * */ function renderPosts($posts, $small = false) { if(!$posts instanceof PageArray) { if($posts instanceof Page) { // single page $post = $posts; $posts = new PageArray(); $posts->add($post); } else if(is_string($posts)) { // selector string $selector = $posts; $posts = wire('pages')->find("template=blog-post, sort=-date, $selector"); } else { throw new WireException('renderPosts requires a PageArray, Page or selector string'); } } foreach($posts as $page) { if(empty($page->summary)) { // summary is blank so we auto-generate a summary from the body $summary = strip_tags(substr($page->body, 0, 450)); $page->summary = substr($summary, 0, strrpos($summary, ' ')); } // set a couple new fields that our output will use $page->set('authorName', $page->createdUser->get('title|name')); $page->set('authorURL', wire('config')->urls->root . 'authors/' . $page->createdUser->name . '/'); } $t = new TemplateFile(wire('config')->paths->templates . '/markup/posts.php'); $t->set('posts', $posts); $t->set('small', $small); $out = $t->render(); // if there are more posts than the specified limit, then output pagination if($posts->getLimit() < $posts->getTotal()) $out .= $posts->renderPager(); return $out; } As you can see, the function makes use of /markup/posts.php. Within posts.php I have the following: // display a headline indicating quantities $start = $posts->getStart()+1; $end = $start + count($posts)-1; $total = $posts->getTotal(); if($total) echo "<h3>" . sprintf(__('Posts %1$d to %2$d of %3$d'), $start, $end, $total) . "</h3>"; This echoes the quantities headline as expected to $content but I would like to have it echoed to my $sidebar variable instead which currently doesn't work as it is part of renderPosts(). My question: What would be the best strategy/solution to assign $total to my $sidebar variable instead to $content? Thanks
  20. Sorry for that messy topic title but my problem seems very complicated to describe in so few words. So here a better description of my issue: I have a many product detail site under a parent called /overview/. On this product detail site is at the footer a listing of all the others product detail sites including the site itself. (all children of the parent /overview/. So i have for example: /overview/test1/ /overview/test2/ /overview/test3/ /overview/test4/ /overview/test5/ My Code look like this at the moment: <?php $overview = $pages->get("/overview/"); $overviewchildren = $overview->children("limit=4"); foreach($overviewchildren as $overviewchild) {?> <a href="<?=$overviewchild->url?>"><?=$overviewchild->title?></a> <?}?> Now on the site /overview/test1/ the code list show test1, test2, test3, test4. But i want that the child on which the user is at the moment dont show up at the list. So for the site /overview/test2/ the list should show test1, test3, test4 and test5. I hope you understand my problem , cause im from germany and to describe a php issue in english is very hard for me. Thanks a lot everybody for helping me.
  21. I just installed ProcessWire for the first time and I've perused the documentation but haven't seen an explanation of the template files that start with an _. Can someone explain to me how those work? Also, how come they have an opening php tag but no closing tag? Is there anything that explains this in depth?
  22. I'm following the FAQ post here / trying to create password protected page. The code they supplied was this: <?php if ($_POST['awesome_password'] != $page->page_password) { echo <<<EOT <h1>Login</h1> <form name='form' method='post' action='$page->url'> <input type='password' title='Enter your password' name='awesome_password' /> <br /> <input type='submit' name='Submit' value='Login' /> </form> EOT; } else { echo "<p>This is the protected page. Content goes here.</p>"; } ?> That works beautifully. However, I want to spit out more than just a simple ECHO in the else statement. In fact, I want some pretty simple Html mixed with php. Now I tried modifying the original code supplied by adding another <<< thinking that it would work but of course it didn't else { echo <<<EOD <!--Begin Table For Catalog Data --> <table id="catalog" class="display" cellspacing="0" width="100%"> <thead> <tr> <th>Artist</th> <th>Track Name</th> <th>Album</th> <th>Length</th> <th>Songwriter(s)</th> <th>Genre</th> <th><span data-tooltip class="has-tip" title="Displays the following mood / emotion / characteristic">Traits</span></th> <th><span data-tooltip class="has-tip" title="All songs are originals unless designated cover (letter C)">Type</span></th> <th></th> </tr> </thead> <tbody> <?php //Table Loops $tracks = $pages->find("has_parent=/artists/, template=track"); if($tracks) { foreach($tracks as $track) { echo "<tr>"; echo "<td id='artistName'>" . $track->parent->parent->title . "</td>"; // artist name echo "<td id='trackTitle'>" . $track->title . "</td>"; echo "<td id='albumTitle'>" . $track->parent->title . "</td>"; // this is the album name echo "<td id='trackLength'>" . $track->track_length . "</td>"; // track length echo "<td>" . $track->songwriter . "</td>"; // track songwriter echo "<td id='genres'>"; foreach ($track->genres as $genre) { echo $genre->title . "/"; }; echo "</td>"; echo "<td id='traits'>"; foreach ($track->moods as $mood) { echo $mood->title . "/ "; }; echo "</td>"; echo "<td>"; // determin cover song or not if($track->song_type != null) { echo '<img id="logo" src="' . $config->urls->templates . 'img/letterC.png">'; } else { echo ""; }; //end determin cover echo "</td>"; echo "<td>" . "<a href=' " . $track->song_file->url . " ' class='sm2_button'>Play</a>" ."</td>"; echo "</tr>"; } } ?> </tbody> </table> <!-- End Catalog Table --> <!-- Initialize DataTable --> <script> $(document).ready(function () { $('#catalog').DataTable(); } ); </script> EOD; } ?> I have never worked with <<< Heredoc syntax before, Apparently you can't put whatever you want between it? No?
  23. Hey, guys. I've been a daily visitor of this forum and have learned a lot from you, thanks for that. \o/ I'm learning php, so I'm quite noob =( , and decided to try and learn it with processwire. I'm loving it. I really enjoy the fact that I can build something based on totally different approaches. But I'm having a problem on how to create and structure a Search. Can someone provide me a few tips on where to begin? Thanks in advance xoxo
  24. I was just curios about how fast PHP handles the different types of string concatenation/parsing with variables, because I saw Ryan's style is double quotes and I was thinking, isn't that slower than single quote concatenation? I was surprised because I remember to have learned that the additional parsing of double quote strings make the whole thing slower. I was wrong, here is my benchmark. Thought it'd be interesting to know. 1000000 times per test // initial object creation, only once $fooObject = new stdClass; $fooObject->foo = "Lorem ipsum dolor sit amet."; $fooObject->bar = "Consectetur adipisicing elit."; $fooObject->baz = "Sed do eiusmod tempor incididunt."; double quotes "foo: {$fooObject->foo}, bar: {$fooObject->bar}, baz: {$fooObject->baz}" 0.55859899520874 s single quotes concat 'foo: ' . $fooObject->foo . ', bar: ' . $fooObject->bar . ', baz: ' . $fooObject->baz 0.61702013015747 s sprintf sprintf("foo: %s, bar: %s, baz: %s", $fooObject->foo, $fooObject->bar, $fooObject->baz) 1.6139810085297 s array implode implode('', array('foo: ', $fooObject->foo, ', bar: ', $fooObject->bar, 'baz: ', $fooObject->baz)) 2.0107381343842 s Code: <?php $times = 1000000; ?> <h1>PHP string concat benchmark</h1> <p><?=$times?> times per test</p> <code><pre> $fooObject = new stdClass; $fooObject->foo = "Lorem ipsum dolor sit amet."; $fooObject->bar = "Consectetur adipisicing elit."; $fooObject->baz = "Sed do eiusmod tempor incididunt."; </pre></code><br> <hr> <?php function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } $fooObject = new stdClass; $fooObject->foo = "Lorem ipsum dolor sit amet."; $fooObject->bar = "Consectetur adipisicing elit."; $fooObject->baz = "Sed do eiusmod tempor incididunt."; $time_start = microtime_float(); for ($i=0; $i < $times; $i++) { $someString = "foo: {$fooObject->foo}, bar: {$fooObject->bar}, baz: {$fooObject->baz}"; } $time_end = microtime_float(); $time = $time_end - $time_start; ?> <h2>double quote</h2> <code>"foo: {$fooObject->foo}, bar: {$fooObject->bar}, baz: {$fooObject->baz}"</code><br><br> <?=$time?> s<br><br> <hr> <?php $time_start = microtime_float(); $someString = ''; for ($i=0; $i < $times; $i++) { $someString = 'foo: ' . $fooObject->foo . ', bar: ' . $fooObject->bar . ', baz: ' . $fooObject->baz; } $time_end = microtime_float(); $time = $time_end - $time_start; ?> <h2>single quote concat</h2> <code>'foo: ' . $fooObject->foo . ', bar: ' . $fooObject->bar . ', baz: ' . $fooObject->baz</code><br><br> <?=$time?> s<br><br> <hr> <?php $time_start = microtime_float(); for ($i=0; $i < $times; $i++) { $someString = sprintf("foo: %s, bar: %s, baz: %s", $fooObject->foo, $fooObject->bar, $fooObject->baz); } $time_end = microtime_float(); $time = $time_end - $time_start; ?> <h2>sprintf</h2> <code>sprintf("foo: %s, bar: %s, baz: %s", $fooObject->foo, $fooObject->bar, $fooObject->baz)</code><br><br> <?=$time?> s<br><br> <hr> <?php $time_start = microtime_float(); for ($i=0; $i < $times; $i++) { $someString = implode('', array('foo: ', $fooObject->foo, ', bar: ', $fooObject->bar, 'baz: ', $fooObject->baz)); } $time_end = microtime_float(); $time = $time_end - $time_start; ?> <h2>array implode</h2> <code>implode('', array('foo: ', $fooObject->foo, ', bar: ', $fooObject->bar, 'baz: ', $fooObject->baz))</code><br><br> <?=$time?> s<br><br>
×
×
  • Create New...