本文整理汇总了PHP中Drupal\Component\Utility\Unicode::strpos方法的典型用法代码示例。如果您正苦于以下问题:PHP Unicode::strpos方法的具体用法?PHP Unicode::strpos怎么用?PHP Unicode::strpos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Component\Utility\Unicode
的用法示例。
在下文中一共展示了Unicode::strpos方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: viewElements
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode)
{
// Define element array.
$element = [];
foreach ($items as $delta => $item) {
// Convert the link-field item to a \Drupal\Core\Url object.
$url = $this->buildUrl($item);
// Parse the URL so we can check if the path contains a Github Gist. We do
// this to check if we should actually render the element or provide a
// notice in the log.
$url = UrlHelper::parse($url->getUri());
if (FALSE !== Unicode::strpos($url['path'], 'gist.github.com')) {
$element[$delta] = ['#theme' => 'gist_embed', '#url' => $url];
} else {
$entity = $items->getEntity();
$message = $this->t('The entity type: "@type" with the ID: "@id" is trying to use a link that isn\'t a Github Gist link for the Gist Embed Formatter.', array('@type' => ucfirst($entity->getEntityType()->id()), '@id' => $entity->id()));
\Drupal::logger('gist_embed')->notice($message);
}
}
return $element;
}
示例2: testStrpos
/**
* Tests multibyte strpos.
*
* @dataProvider providerStrpos
* @covers ::strpos
*/
public function testStrpos($haystack, $needle, $offset, $expected)
{
// Run through multibyte code path.
Unicode::setStatus(Unicode::STATUS_MULTIBYTE);
$this->assertEquals($expected, Unicode::strpos($haystack, $needle, $offset));
// Run through singlebyte code path.
Unicode::setStatus(Unicode::STATUS_SINGLEBYTE);
$this->assertEquals($expected, Unicode::strpos($haystack, $needle, $offset));
}