本文整理匯總了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));
}