本文整理汇总了PHP中String::strpos方法的典型用法代码示例。如果您正苦于以下问题:PHP String::strpos方法的具体用法?PHP String::strpos怎么用?PHP String::strpos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String::strpos方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateFileName
/**
* Generate a filename for a library file.
* @param $type int LIBRARY_FILE_TYPE_...
* @param $originalFileName string
* @return string
*/
function generateFileName($type, $originalFileName)
{
$libraryFileDao =& DAORegistry::getDAO('LibraryFileDAO');
$suffix = $this->getFileSuffixFromType($type);
$ext = $this->getExtension($originalFileName);
$truncated = $this->truncateFileName($originalFileName, 127 - String::strlen($suffix) - 1);
$baseName = String::substr($truncated, 0, String::strpos($originalFileName, $ext) - 1);
// Try a simple syntax first
$fileName = $baseName . '-' . $suffix . '.' . $ext;
if (!$libraryFileDao->filenameExists($this->pressId, $fileName)) {
return $fileName;
}
for ($i = 1;; $i++) {
$fullSuffix = $suffix . '-' . $i;
//truncate more if necessary
$truncated = $this->truncateFileName($originalFileName, 127 - String::strlen($fullSuffix) - 1);
// get the base name and append the suffix
$baseName = String::substr($truncated, 0, String::strpos($originalFileName, $ext) - 1);
//try the following
$fileName = $baseName . '-' . $fullSuffix . '.' . $ext;
if (!$libraryFileDao->filenameExists($this->pressId, $fileName)) {
return $fileName;
}
}
}
示例2: getNewestCompatible
/**
* Get a set of GalleryPlugin objects describing the available
* compatible plugins in their newest versions.
* @param $application PKPApplication
* @param $category string Optional category name to use as filter
* @param $search string Optional text to use as filter
* @return array GalleryPlugin objects
*/
function getNewestCompatible($application, $category = null, $search = null)
{
$doc = $this->_getDocument();
$plugins = array();
foreach ($doc->getElementsByTagName('plugin') as $element) {
$plugin = $this->_compatibleFromElement($element, $application);
// May be null if no compatible version exists; also
// apply search filters if any supplied.
if ($plugin && ($category == '' || $plugin->getCategory() == $category) && ($search == '' || String::strpos(String::strtolower(serialize($plugin)), String::strtolower($search)) !== false)) {
$plugins[] = $plugin;
}
}
return $plugins;
}
示例3: _removeTagsAux
/**
* Helper function: Recursive function called by _removeTags
* @author Matt Crider
* @param string
* @param int
* @param array
* @param int
* @return string
*/
function _removeTagsAux($string, $loc, &$tags, $length)
{
if (strlen($string) > 0 && $length > 0) {
$length--;
if (String::substr($string, 0, 1) == '<') {
$closeBrack = String::strpos($string, '>') + 1;
if ($closeBrack) {
$tags[] = array(String::substr($string, 0, $closeBrack), $loc);
return $this->_removeTagsAux(String::substr($string, $closeBrack), $loc + $closeBrack, $tags, $length);
}
}
return String::substr($string, 0, 1) . $this->_removeTagsAux(String::substr($string, 1), $loc + 1, $tags, $length);
}
}
示例4: _removeTagsAux
/**
* Helper function: Recursive function called by _removeTags
* @author Matt Crider
* @param string
* @param int
* @param array
* @param int
* @return string
*/
function _removeTagsAux($string, $loc, &$tags, $length)
{
$newString = '';
for ($i = 0; $i < strlen($string); $i++) {
if (String::substr($string, $i, 1) == '<') {
// We've found the beginning of an HTML tag, find the position of its ending
$closeBrack = String::strpos($string, '>', $i);
if ($closeBrack) {
// Add the tag and its position to the tags array reference
$tags[] = array(String::substr($string, $i, $closeBrack - $i + 1), $i);
$i += $closeBrack - $i;
continue;
}
}
$length--;
$newString = $newString . String::substr($string, $i, 1);
}
return $newString;
}
示例5: array
/**
* Fills the given citation object with
* meta-data retrieved from PubMed.
* @param $pmid string
* @param $citationDescription MetadataDescription
* @return MetadataDescription
*/
function &_lookup($pmid, &$citationDescription)
{
$nullVar = null;
// Use eFetch to get XML metadata for the given PMID
$lookupParams = array('db' => 'pubmed', 'mode' => 'xml', 'tool' => 'pkp-wal', 'id' => $pmid);
if (!is_null($this->getEmail())) {
$lookupParams['email'] = $this->getEmail();
}
// Call the eFetch URL and get an XML result
if (is_null($resultDOM = $this->callWebService(PUBMED_WEBSERVICE_EFETCH, $lookupParams))) {
return $nullVar;
}
$metadata = array('pub-id[@pub-id-type="pmid"]' => $pmid, 'article-title' => $resultDOM->getElementsByTagName("ArticleTitle")->item(0)->textContent, 'source' => $resultDOM->getElementsByTagName("MedlineTA")->item(0)->textContent);
if ($resultDOM->getElementsByTagName("Volume")->length > 0) {
$metadata['volume'] = $resultDOM->getElementsByTagName("Volume")->item(0)->textContent;
}
if ($resultDOM->getElementsByTagName("Issue")->length > 0) {
$metadata['issue'] = $resultDOM->getElementsByTagName("Issue")->item(0)->textContent;
}
// get list of author full names
$nlmNameSchema = new NlmNameSchema();
foreach ($resultDOM->getElementsByTagName("Author") as $authorNode) {
if (!isset($metadata['person-group[@person-group-type="author"]'])) {
$metadata['person-group[@person-group-type="author"]'] = array();
}
// Instantiate an NLM name description
$authorDescription = new MetadataDescription($nlmNameSchema, ASSOC_TYPE_AUTHOR);
// Surname
$authorDescription->addStatement('surname', $authorNode->getElementsByTagName("LastName")->item(0)->textContent);
// Given names
$givenNamesString = '';
if ($authorNode->getElementsByTagName("FirstName")->length > 0) {
$givenNamesString = $authorNode->getElementsByTagName("FirstName")->item(0)->textContent;
} elseif ($authorNode->getElementsByTagName("ForeName")->length > 0) {
$givenNamesString = $authorNode->getElementsByTagName("ForeName")->item(0)->textContent;
}
if (!empty($givenNamesString)) {
foreach (explode(' ', $givenNamesString) as $givenName) {
$authorDescription->addStatement('given-names', String::trimPunctuation($givenName));
}
}
// Suffix
if ($authorNode->getElementsByTagName("Suffix")->length > 0) {
$authorDescription->addStatement('suffix', $authorNode->getElementsByTagName("Suffix")->item(0)->textContent);
}
// Include collective names
/*if ($resultDOM->getElementsByTagName("CollectiveName")->length > 0 && $authorNode->getElementsByTagName("CollectiveName")->item(0)->textContent != '') {
// FIXME: This corresponds to an NLM-citation <collab> tag and should be part of the Metadata implementation
}*/
$metadata['person-group[@person-group-type="author"]'][] =& $authorDescription;
unset($authorDescription);
}
// Extract pagination
if (String::regexp_match_get("/^[:p\\.\\s]*(?P<fpage>[Ee]?\\d+)(-(?P<lpage>\\d+))?/", $resultDOM->getElementsByTagName("MedlinePgn")->item(0)->textContent, $pages)) {
$fPage = (int) $pages['fpage'];
$metadata['fpage'] = $fPage;
if (!empty($pages['lpage'])) {
$lPage = (int) $pages['lpage'];
// Deal with shortcuts like '382-7'
if ($lPage < $fPage) {
$lPage = (int) (String::substr($pages['fpage'], 0, -String::strlen($pages['lpage'])) . $pages['lpage']);
}
$metadata['lpage'] = $lPage;
}
}
// Get publication date
// TODO: The publication date could be in multiple places
if ($resultDOM->getElementsByTagName("ArticleDate")->length > 0) {
$publicationDate = $resultDOM->getElementsByTagName("ArticleDate")->item(0)->getElementsByTagName("Year")->item(0)->textContent . '-' . $resultDOM->getElementsByTagName("ArticleDate")->item(0)->getElementsByTagName("Month")->item(0)->textContent . '-' . $resultDOM->getElementsByTagName("ArticleDate")->item(0)->getElementsByTagName("Day")->item(0)->textContent;
$metadata['date'] = $publicationDate;
}
// Get publication type
if ($resultDOM->getElementsByTagName("PublicationType")->length > 0) {
foreach ($resultDOM->getElementsByTagName("PublicationType") as $publicationType) {
// The vast majority of items on PubMed are articles so catch these...
if (String::strpos(String::strtolower($publicationType->textContent), 'article') !== false) {
$metadata['[@publication-type]'] = NLM_PUBLICATION_TYPE_JOURNAL;
break;
}
}
}
// Get DOI if it exists
foreach ($resultDOM->getElementsByTagName("ArticleId") as $idNode) {
if ($idNode->getAttribute('IdType') == 'doi') {
$metadata['pub-id[@pub-id-type="doi"]'] = $idNode->textContent;
}
}
// Use eLink utility to find fulltext links
$lookupParams = array('dbfrom' => 'pubmed', 'cmd' => 'llinks', 'tool' => 'pkp-wal', 'id' => $pmid);
if (!is_null($resultDOM = $this->callWebService(PUBMED_WEBSERVICE_ELINK, $lookupParams))) {
// Get a list of possible links
foreach ($resultDOM->getElementsByTagName("ObjUrl") as $linkOut) {
$attributes = '';
//.........这里部分代码省略.........
示例6: array
//.........这里部分代码省略.........
}*/
$metadata['person-group[@person-group-type="author"]'][] =& $authorDescription;
unset($authorDescription);
}
// Extract pagination
$medlinePgnNodes =& $resultDOM->getElementsByTagName("MedlinePgn");
$medlinePgnFirstNode =& $medlinePgnNodes->item(0);
if (String::regexp_match_get("/^[:p\\.\\s]*(?P<fpage>[Ee]?\\d+)(-(?P<lpage>\\d+))?/", $medlinePgnFirstNode->textContent, $pages)) {
$fPage = (int) $pages['fpage'];
$metadata['fpage'] = $fPage;
if (!empty($pages['lpage'])) {
$lPage = (int) $pages['lpage'];
// Deal with shortcuts like '382-7'
if ($lPage < $fPage) {
$lPage = (int) (String::substr($pages['fpage'], 0, -String::strlen($pages['lpage'])) . $pages['lpage']);
}
$metadata['lpage'] = $lPage;
}
}
// Get publication date (can be in several places in PubMed).
$dateNode = null;
$articleDateNodes =& $resultDOM->getElementsByTagName("ArticleDate");
if ($articleDateNodes->length > 0) {
$dateNode =& $articleDateNodes->item(0);
} else {
$pubDateNodes =& $resultDOM->getElementsByTagName("PubDate");
if ($pubDateNodes->length > 0) {
$dateNode =& $pubDateNodes->item(0);
}
}
// Retrieve the data parts and assemble date.
if (!is_null($dateNode)) {
$publicationDate = '';
$requiresNormalization = false;
foreach (array('Year' => 4, 'Month' => 2, 'Day' => 2) as $dateElement => $padding) {
$dateElementNodes =& $dateNode->getElementsByTagName($dateElement);
if ($dateElementNodes->length > 0) {
if (!empty($publicationDate)) {
$publicationDate .= '-';
}
$dateElementFirstNode =& $dateElementNodes->item(0);
$datePart = str_pad($dateElementFirstNode->textContent, $padding, '0', STR_PAD_LEFT);
if (!is_numeric($datePart)) {
$requiresNormalization = true;
}
$publicationDate .= $datePart;
} else {
break;
}
}
// Normalize the date to NLM standard if necessary.
if ($requiresNormalization) {
$dateFilter = new DateStringNormalizerFilter();
$publicationDate = $dateFilter->execute($publicationDate);
}
if (!empty($publicationDate)) {
$metadata['date'] = $publicationDate;
}
}
// Get publication type
$publicationTypeNodes =& $resultDOM->getElementsByTagName("PublicationType");
if ($publicationTypeNodes->length > 0) {
foreach ($publicationTypeNodes as $publicationType) {
// The vast majority of items on PubMed are articles so catch these...
if (String::strpos(String::strtolower($publicationType->textContent), 'article') !== false) {
$metadata['[@publication-type]'] = NLM30_PUBLICATION_TYPE_JOURNAL;
break;
}
}
}
// Get DOI if it exists
$articleIdNodes =& $resultDOM->getElementsByTagName("ArticleId");
foreach ($articleIdNodes as $idNode) {
if ($idNode->getAttribute('IdType') == 'doi') {
$metadata['pub-id[@pub-id-type="doi"]'] = $idNode->textContent;
}
}
// Use eLink utility to find fulltext links
$lookupParams = array('dbfrom' => 'pubmed', 'cmd' => 'llinks', 'tool' => 'pkp-wal', 'id' => $pmid);
if (!is_null($resultDOM = $this->callWebService(PUBMED_WEBSERVICE_ELINK, $lookupParams))) {
// Get a list of possible links
foreach ($resultDOM->getElementsByTagName("ObjUrl") as $linkOut) {
$attributes = '';
foreach ($linkOut->getElementsByTagName("Attribute") as $attribute) {
$attributes .= String::strtolower($attribute->textContent) . ' / ';
}
// Only add links to open access resources
if (String::strpos($attributes, "subscription") === false && String::strpos($attributes, "membership") === false && String::strpos($attributes, "fee") === false && $attributes != "") {
$urlNodes =& $linkOut->getElementsByTagName("Url");
$urlFirstNode =& $urlNodes->item(0);
$links[] = $urlFirstNode->textContent;
}
}
// Take the first link if we have any left (presumably pubmed returns them in preferential order)
if (isset($links[0])) {
$metadata['uri'] = $links[0];
}
}
return $this->getNlm30CitationDescriptionFromMetadataArray($metadata);
}
示例7: getResolvingURL
/**
* @see PubIdPlugin::getResolvingURL()
*/
function getResolvingURL($journalId, $pubId)
{
// See ANSI/NISO Z39.84-2005, Appendix E. (Bug #8190)
$separatorIndex = String::strpos($pubId, '/');
assert($separatorIndex !== false);
// Should contain a slash
$prefix = String::substr($pubId, 0, $separatorIndex);
$suffix = String::substr($pubId, $separatorIndex + 1);
return 'http://dx.doi.org/' . $prefix . '/' . urlencode($suffix);
}
示例8: testOffsetStringPosition
function testOffsetStringPosition()
{
$string = 'abcdabcdabcd';
$find = 'a';
$result = String::strpos($string, $find, 5);
$expected = 8;
$this->assertEqual($result, $expected);
$string = '¡¢£¤¡¢£¤¡¢£¤';
$find = '¡';
$result = String::strpos($string, $find, 5);
$expected = 8;
$this->assertEqual($result, $expected);
$string = 'ÉÊËÌÉÊËÌÉÊËÌ';
$find = 'É';
$result = String::strpos($string, $find, 5);
$expected = 8;
$this->assertEqual($result, $expected);
$string = 'ĭĮįİĭĮįİĭĮįİ';
$find = 'ĭ';
$result = String::strpos($string, $find, 5);
$expected = 8;
$this->assertEqual($result, $expected);
$string = 'ƑƒƓƔƑƒƓƔƑƒƓƔ';
$find = 'Ƒ';
$result = String::strpos($string, $find, 5);
$expected = 8;
$this->assertEqual($result, $expected);
$string = 'əɚɛɜəɚɛɜəɚɛɜ';
$find = 'ə';
$result = String::strpos($string, $find, 5);
$expected = 8;
$this->assertEqual($result, $expected);
$string = 'ЀЁЂЃЀЁЂЃЀЁЂЃ';
$find = 'Ѐ';
$result = String::strpos($string, $find, 5);
$expected = 8;
$this->assertEqual($result, $expected);
$string = 'МНОПМНОПМНОП';
$find = 'М';
$result = String::strpos($string, $find, 5);
$expected = 8;
$this->assertEqual($result, $expected);
$string = 'չպջռչպջռչպջռ';
$find = 'չ';
$result = String::strpos($string, $find, 5);
$expected = 8;
$this->assertEqual($result, $expected);
$string = 'فقكلفقكلفقكل';
$find = 'ف';
$result = String::strpos($string, $find, 5);
$expected = 8;
$this->assertEqual($result, $expected);
$string = '✰✱✲✳✰✱✲✳✰✱✲✳';
$find = '✰';
$result = String::strpos($string, $find, 5);
$expected = 8;
$this->assertEqual($result, $expected);
$string = '⺀⺁⺂⺃⺀⺁⺂⺃⺀⺁⺂⺃';
$find = '⺀';
$result = String::strpos($string, $find, 5);
$expected = 8;
$this->assertEqual($result, $expected);
$string = '⽅⽆⽇⽈⽅⽆⽇⽈⽅⽆⽇⽈';
$find = '⽅';
$result = String::strpos($string, $find, 5);
$expected = 8;
$this->assertEqual($result, $expected);
$string = '눡눢눣눤눡눢눣눤눡눢눣눤';
$find = '눡';
$result = String::strpos($string, $find, 5);
$expected = 8;
$this->assertEqual($result, $expected);
$string = 'ﹲﹳﹴﹲﹳﹴﹲﹳﹴ';
$find = 'ﹲ';
$result = String::strpos($string, $find, 5);
$expected = 8;
$this->assertEqual($result, $expected);
$string = 'ﻓﻔﻕﻖﻓﻔﻕﻖﻓﻔﻕﻖ';
$find = 'ﻓ';
$result = String::strpos($string, $find, 5);
$expected = 8;
$this->assertEqual($result, $expected);
$string = 'abcdabcdabcd';
$find = 'a';
$result = String::strpos($string, $find, 5);
$expected = 8;
$this->assertEqual($result, $expected);
$string = 'ィゥェォィゥェォィゥェォ';
$find = 'ィ';
$result = String::strpos($string, $find, 5);
$expected = 8;
$this->assertEqual($result, $expected);
$string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
$find = 'ル';
$result = String::strpos($string, $find);
$expected = 32;
$this->assertEqual($result, $expected);
$string = '𐐀𐐁𐐀𐐁𐐀𐐁';
$find = '';
$result = String::strpos($string, $find, 5);
//.........这里部分代码省略.........