当前位置: 首页>>代码示例>>PHP>>正文


PHP str函数代码示例

本文整理汇总了PHP中str函数的典型用法代码示例。如果您正苦于以下问题:PHP str函数的具体用法?PHP str怎么用?PHP str使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了str函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test

 /**
  * Stack test method.
  *
  * @param object IStack $stack The stack to test.
  */
 public static function test(IStack $stack)
 {
     printf("AbstractStack test program.\n");
     for ($i = 0; $i < 6; ++$i) {
         if ($stack->isFull()) {
             break;
         }
         $stack->push(box($i));
     }
     printf("%s\n", str($stack));
     printf("Using foreach\n");
     foreach ($stack as $obj) {
         printf("%s\n", str($obj));
     }
     printf("Using reduce\n");
     $stack->reduce(create_function('$sum,$obj', 'printf("%s\\n", str($obj));'), '');
     printf("Top is %s\n", str($stack->getTop()));
     printf("Popping\n");
     while (!$stack->isEmpty()) {
         $obj = $stack->pop();
         printf("%s\n", str($obj));
     }
     $stack->push(box(2));
     $stack->push(box(4));
     $stack->push(box(6));
     printf("%s\n", str($stack));
     printf("Purging\n");
     $stack->purge();
     printf("%s\n", str($stack));
 }
开发者ID:EdenChan,项目名称:Instances,代码行数:35,代码来源:AbstractStack.php

示例2: test

 /**
  * PriorityQueue test method.
  *
  * @param object IPriorityQueue $pqueue The queue to test.
  */
 public static function test(IPriorityQueue $pqueue)
 {
     printf("AbstractPriorityQueue test program.\n");
     printf("%s\n", str($pqueue));
     $pqueue->enqueue(box(3));
     $pqueue->enqueue(box(1));
     $pqueue->enqueue(box(4));
     $pqueue->enqueue(box(1));
     $pqueue->enqueue(box(5));
     $pqueue->enqueue(box(9));
     $pqueue->enqueue(box(2));
     $pqueue->enqueue(box(6));
     $pqueue->enqueue(box(5));
     $pqueue->enqueue(box(4));
     printf("%s\n", str($pqueue));
     printf("Using reduce\n");
     $pqueue->reduce(create_function('$sum,$obj', 'printf("%s\\n", str($obj));'), '');
     printf("Using foreach\n");
     foreach ($pqueue as $obj) {
         printf("%s\n", str($obj));
     }
     printf("Dequeueing\n");
     while (!$pqueue->isEmpty()) {
         $obj = $pqueue->dequeueMin();
         printf("%s\n", str($obj));
     }
 }
开发者ID:EdenChan,项目名称:Instances,代码行数:32,代码来源:AbstractPriorityQueue.php

示例3: flush

 /**
  * @see Log
  */
 public function flush($logs, $id, $stdout)
 {
     foreach ($logs as $log) {
         try {
             $vars = $options = array();
             foreach (module_const_array('params') as $param) {
                 list($name, $value) = array_map('trim', explode(',', $param, 2));
                 $vars[$name] = $value;
             }
             $vars['level'] = $log->fm_level();
             $value = $log->value();
             if (is_array($value)) {
                 $value = array_shift($value);
             }
             switch ($log->fm_level()) {
                 case 'error':
                 case 'warn':
                 case 'info':
                     $vars['priv'] = 1;
                     $vars['message'] = sprintf("%s:%s %s", pathinfo($log->file(), PATHINFO_FILENAME), $log->line(), str($value));
                     break;
             }
             if (isset($vars['message'])) {
                 $data = http_build_query($vars);
                 $header = array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($data));
                 $options = array('http' => array('method' => 'POST', 'header' => implode("\r\n", $header), 'content' => $data));
                 file_get_contents(module_const('url'), false, stream_context_create($options));
             }
         } catch (Exception $e) {
         }
         // print(sprintf('console.%s("[%s:%d]",%s);',$log->fm_level(),$log->file(),$log->line(),str_replace("\n","\\n",Text::to_json($log->value()))));
     }
 }
开发者ID:nequal,项目名称:Openpear,代码行数:36,代码来源:LogIrcNotice.php

示例4: main

 /**
  * Main program.
  *
  * @param array $args Command-line arguments.
  * @return integer Zero on success; non-zero on failure.
  */
 public static function main($args)
 {
     printf("Application program number 3.\n");
     $status = 0;
     $p1 = new PolynomialAsOrderedList();
     $p1->add(new Term(4.5, 5));
     $p1->add(new Term(3.2, 14));
     printf("%s\n", str($p1));
     $p1->differentiate();
     printf("%s\n", str($p1));
     $p2 = new PolynomialAsSortedList();
     $p2->add(new Term(7.8, 0));
     $p2->add(new Term(1.6, 14));
     $p2->add(new Term(9.999000000000001, 27));
     printf("%s\n", str($p2));
     $p2->differentiate();
     printf("%s\n", str($p2));
     $p3 = new PolynomialAsSortedList();
     $p3->add(new Term(0.6, 13));
     $p3->add(new Term(-269.973, 26));
     $p3->add(new Term(1000, 1000));
     printf("%s\n", str($p3));
     printf("%s\n", str($p2->plus($p3)));
     return $status;
 }
开发者ID:EdenChan,项目名称:Instances,代码行数:31,代码来源:Application3.php

示例5: test

 /**
  * Search tree test program.
  *
  * @param object ISearchTree $tree The tree to test.
  */
 public static function test(ISearchTree $tree)
 {
     printf("AbstractSearchTree test program.\n");
     printf("%s\n", str($tree));
     for ($i = 1; $i <= 8; ++$i) {
         $tree->insert(box($i));
     }
     printf("%s\n", str($tree));
     printf("Breadth-First traversal\n");
     $tree->breadthFirstTraversal(new PrintingVisitor(STDOUT));
     printf("Preorder traversal\n");
     $tree->depthFirstTraversal(new PreOrder(new PrintingVisitor(STDOUT)));
     printf("Inorder traversal\n");
     $tree->depthFirstTraversal(new InOrder(new PrintingVisitor(STDOUT)));
     printf("Postorder traversal\n");
     $tree->depthFirstTraversal(new PostOrder(new PrintingVisitor(STDOUT)));
     printf("Using foreach\n");
     foreach ($tree as $obj) {
         printf("%s\n", str($obj));
     }
     printf("Using reduce\n");
     $tree->reduce(create_function('$sum,$obj', 'printf("%s\\n", str($obj));'), '');
     printf("Using accept\n");
     $tree->accept(new ReducingVisitor(create_function('$sum,$obj', 'printf("%s\\n", str($obj));'), ''));
     printf("Withdrawing 4\n");
     $obj = $tree->find(box(4));
     try {
         $tree->withdraw($obj);
         printf("%s\n", str($tree));
     } catch (Exception $e) {
         printf("Caught %s\n", $e->getMessage());
     }
 }
开发者ID:EdenChan,项目名称:Instances,代码行数:38,代码来源:AbstractSearchTree.php

示例6: test

 /**
  * OrderedList test method.
  *
  * @param object IOrderedList $list The list to test.
  */
 public static function test(IOrderedList $list)
 {
     printf("AbstractOrderedList test program.\n");
     $list->insert(box(1));
     $list->insert(box(2));
     $list->insert(box(3));
     $list->insert(box(4));
     printf("%s\n", str($list));
     $obj = $list->find(box(2));
     $list->withdraw($obj);
     printf("%s\n", str($list));
     $position = $list->findPosition(box(3));
     $position->insertAfter(box(5));
     printf("%s\n", str($list));
     $position->insertBefore(box(6));
     printf("%s\n", str($list));
     $position->withdraw();
     printf("%s\n", str($list));
     printf("Using foreach\n");
     foreach ($list as $obj) {
         printf("%s\n", str($obj));
     }
     printf("Using reduce\n");
     $list->reduce(create_function('$sum,$obj', 'printf("%s\\n", str($obj));'), '');
 }
开发者ID:EdenChan,项目名称:Instances,代码行数:30,代码来源:AbstractOrderedList.php

示例7: main

 /**
  * Main program.
  *
  * @param array $args Command-line arguments.
  * @return integer Zero on success; non-zero on failure.
  */
 public static function main($args)
 {
     printf("Application program number 6. (expression tree)\n");
     $status = 0;
     $expression = ExpressionTree::parsePostfix(STDIN);
     printf("%s\n", str($expression));
     return $status;
 }
开发者ID:EdenChan,项目名称:Instances,代码行数:14,代码来源:Application6.php

示例8: set_charge

 public function set_charge(OpenpearCharge $charge)
 {
     $this->handlename($charge->maintainer()->name());
     $this->name(str($charge->maintainer()));
     $this->mail($charge->maintainer()->mail());
     $this->role($charge->role());
     return $this;
 }
开发者ID:nequal,项目名称:Openpear,代码行数:8,代码来源:PackageProjectorConfigMaintainer.php

示例9: test

 /**
  * Digraph test method.
  *
  * @param object IDigraph $g The digraph to test.
  */
 public static function test(IDigraph $g)
 {
     printf("Digraph test program.\n");
     AbstractGraph::Test($g);
     printf("TopologicalOrderTraversal\n");
     $g->topologicalOrderTraversal(new PrintingVisitor(STDOUT));
     printf("isCyclic returns %s\n", str($g->isCyclic()));
     printf("isStronglyConnected returns %s\n", str($g->isStronglyConnected()));
 }
开发者ID:EdenChan,项目名称:Instances,代码行数:14,代码来源:AbstractDigraph.php

示例10: platform_new

function platform_new($nom)
{
    try {
        $result = sql_do('INSERT INTO ' . DB_PREF . '_platforms (name_pf) VALUES (\'' . str($nom) . '\')');
    } catch (DatabaseException $e) {
        return 0;
    }
    return sql_last_id();
}
开发者ID:BackupTheBerlios,项目名称:igoan-svn,代码行数:9,代码来源:Platform.class.php

示例11: testCanBeInstantiated

 public function testCanBeInstantiated()
 {
     $string = new StringBuffer('string');
     $this->assertEquals('string', $string->get());
     $string = new StringBuffer(new TestToStringObject());
     $this->assertEquals('string', $string->get());
     $string = str('string');
     $this->assertEquals('string', $string->get());
 }
开发者ID:laraplus,项目名称:string,代码行数:9,代码来源:SupportStringBufferTest.php

示例12: license_new

function license_new($nom, $term)
{
    try {
        sql_do('INSERT INTO ' . DB_PREF . '_licenses (name_lic,terms) VALUES (\'' . str($nom) . '\',\'' . str($term) . '\')');
    } catch (DatabaseException $e) {
        return 0;
    }
    return sql_last_id();
}
开发者ID:BackupTheBerlios,项目名称:igoan-svn,代码行数:9,代码来源:License.class.php

示例13: language_new

function language_new($nom)
{
    try {
        sql_do('INSERT INTO ' . DB_PREF . '_languages (name_lang) VALUES (\'' . str($nom) . '\')');
    } catch (DatabaseException $e) {
        return 0;
    }
    return sql_last_id();
}
开发者ID:BackupTheBerlios,项目名称:igoan-svn,代码行数:9,代码来源:Language.class.php

示例14: license_new

function license_new($nom, $term)
{
    $id_lic = pick_id('licenses_id_lic_seq');
    try {
        sql_do('INSERT INTO licenses (id_lic,name_lic,terms) VALUES (\'' . int($id_lic) . '\',\'' . str($nom) . '\',\'' . str($term) . '\')');
    } catch (DatabaseException $e) {
        return 0;
    }
    return $id_lic;
}
开发者ID:BackupTheBerlios,项目名称:igoan,代码行数:10,代码来源:License.class.php

示例15: language_new

function language_new($nom)
{
    $id_lang = pick_id('languages_id_lang_seq');
    try {
        sql_do('INSERT INTO languages (id_lang,name_lang) VALUES (' . int($id_lang) . ',\'' . str($nom) . '\')');
    } catch (DatabaseException $e) {
        return 0;
    }
    return $id_lang;
}
开发者ID:BackupTheBerlios,项目名称:igoan-svn,代码行数:10,代码来源:Language.class.php


注:本文中的str函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。