2022-03-22 20:34:02 +00:00
<!DOCTYPE html>
< html class = "no-js" lang = "en" >
< head >
< title > Helper functions - RSS-Bridge< / title >
< meta name = "description" content = "The RSS feed for websites missing it" >
< meta name = "author" content = "RSS-Bridge Contributors" >
< meta charset = "UTF-8" >
< meta http-equiv = "X-UA-Compatible" content = "IE=edge" >
< link rel = "icon" href = "../themes/daux/img/favicon-blue.png" type = "image/x-icon" >
<!-- Mobile -->
< meta name = "apple-mobile-web-app-capable" content = "yes" / >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
<!-- JS -->
< script >
window.base_url = "../";
document.documentElement.classList.remove('no-js');
< / script >
<!-- Font -->
<!-- CSS -->
< link href = '../themes/daux/css/theme-blue.min.css' rel = 'stylesheet' type = 'text/css' >
< link href = '../daux_libraries/search.css' rel = 'stylesheet' type = 'text/css' >
< / head >
< body class = "" >
< div class = "Columns content" >
< aside class = "Columns__left Collapsible" >
< button type = "button" class = "Button Collapsible__trigger" aria-controls = "sidebar_content" aria-expanded = "false" aria-label = "Toggle navigation" >
< span class = "Collapsible__trigger__bar" > < / span >
< span class = "Collapsible__trigger__bar" > < / span >
< span class = "Collapsible__trigger__bar" > < / span >
< / button >
< a class = "Brand" href = "../index.html" > RSS-Bridge< / a >
< form role = 'search' action = "/" method = "get" class = "Search" id = "search_form" >
< label for = "search_input" >
< span class = 'u-visuallyHidden' > Search< / span >
< / label >
< input
type="search"
id="search_input"
class="Search__field"
placeholder="Search..."
aria-label="Search..."
autocomplete="on"
results=25
autosave=text_search
>
< label >
< input type = "submit" class = 'u-visuallyHidden' / >
< span class = 'u-visuallyHidden' > Search...< / span >
< svg class = "Search__icon" xmlns = "http://www.w3.org/2000/svg" viewBox = "0 0 451 451" >
< path d = "M447.05 428l-109.6-109.6c29.4-33.8 47.2-77.9 47.2-126.1C384.65 86.2 298.35 0 192.35 0 86.25 0 .05 86.3.05 192.3s86.3 192.3 192.3 192.3c48.2 0 92.3-17.8 126.1-47.2L428.05 447c2.6 2.6 6.1 4 9.5 4s6.9-1.3 9.5-4c5.2-5.2 5.2-13.8 0-19zM26.95 192.3c0-91.2 74.2-165.3 165.3-165.3 91.2 0 165.3 74.2 165.3 165.3s-74.1 165.4-165.3 165.4c-91.1 0-165.3-74.2-165.3-165.4z" / >
< / svg >
< / label >
< / form >
< div class = "Collapsible__content" id = "sidebar_content" >
<!-- Navigation -->
2025-01-04 18:00:48 +00:00
< ul class = 'Nav' > < li class = 'Nav__item has-children' > < a href = "../General/Project_goals.html" class = "Nav__item__link" > < i class = "Nav__arrow" > < / i > General< / a > < ul class = 'Nav' > < li class = 'Nav__item ' > < a href = "../General/Project_goals.html" > Project-goals< / a > < / li > < li class = 'Nav__item ' > < a href = "../General/Contribute.html" > Contribute< / a > < / li > < li class = 'Nav__item ' > < a href = "../General/Requirements.html" > Requirements< / a > < / li > < li class = 'Nav__item ' > < a href = "../General/Screenshots.html" > Screenshots< / a > < / li > < li class = 'Nav__item ' > < a href = "../General/FAQ.html" > FAQ< / a > < / li > < li class = 'Nav__item ' > < a href = "../General/Public_Hosts.html" > Public Hosts< / a > < / li > < / ul > < / li > < li class = 'Nav__item ' > < a href = "../CLI/index.html" class = "Nav__item__link" > < i class = "Nav__arrow" > < / i > CLI< / a > < ul class = 'Nav' > < / ul > < / li > < li class = 'Nav__item has-children' > < a href = "../For_Hosts/index.html" class = "Nav__item__link" > < i class = "Nav__arrow" > < / i > For Hosts< / a > < ul class = 'Nav' > < li class = 'Nav__item ' > < a href = "../For_Hosts/Installation.html" > Installation< / a > < / li > < li class = 'Nav__item ' > < a href = "../For_Hosts/Updating.html" > Updating< / a > < / li > < li class = 'Nav__item ' > < a href = "../For_Hosts/Heroku_Installation.html" > Heroku Installation< / a > < / li > < li class = 'Nav__item ' > < a href = "../For_Hosts/Whitelisting.html" > Whitelisting< / a > < / li > < li class = 'Nav__item ' > < a href = "../For_Hosts/Authentication.html" > Authentication< / a > < / li > < li class = 'Nav__item ' > < a href = "../For_Hosts/Customizations.html" > Customizations< / a > < / li > < li class = 'Nav__item ' > < a href = "../For_Hosts/Custom_Configuration.html" > Custom Configuration< / a > < / li > < / ul > < / li > < li class = 'Nav__item has-children' > < a href = "../For_Developers/index.html" class = "Nav__item__link" > < i class = "Nav__arrow" > < / i > For Developers< / a > < ul class = 'Nav' > < li class = 'Nav__item ' > < a href = "../For_Developers/Coding_style_policy.html" > Coding style policy< / a > < / li > < li class = 'Nav__item ' > < a href = "../For_Developers/Pull_Request_policy.html" > Pull Request policy< / a > < / li > < li class = 'Nav__item ' > < a href = "../For_Developers/Folder_structure.html" > Folder structure< / a > < / li > < li class = 'Nav__item ' > < a href = "../For_Developers/Actions.html" > Actions< / a > < / li > < li class = 'Nav__item ' > < a href = "../For_Developers/Debug_mode.html" > Debug mode< / a > < / li > < li class = 'Nav__item ' > < a href = "../For_Developers/Github_Codespaces_Tutorial.html" > Github Codespaces Tutorial< / a > < / li > < li class = 'Nav__item ' > < a href = "../For_Developers/Development_Environment_Setup.html" > Development Environment Setup< / a > < / li > < / ul > < / li > < li class = 'Nav__item has-children' > < a href = "../Bridge_API/index.html" class = "Nav__item__link" > < i class = "Nav__arrow" > < / i > Bridge API< / a > < ul class = 'Nav' > < li class = 'Nav__item ' > < a href = "../Bridge_API/How_to_create_a_new_bridge.html" > How to create a new bridge< / a > < / li > < li class = 'Nav__item ' > < a href = "../Bridge_API/BridgeAbstract.html" > BridgeAbstract< / a > < / li > < li class = 'Nav__item ' > < a href = "../Bridge_API/FeedExpander.html" > FeedExpander< / a > < / li > < li class = 'Nav__item ' > < a href = "../Bridge_API/WebDriverAbstract.html" > WebDriverAbstract< / a > < / li > < li class = 'Nav__item ' > < a href = "../Bridge_API/XPathAbstract.html" > XPathAbstract< / a > < / li > < / ul > < / li > < li class = 'Nav__item Nav__item--open' > < a href = "../Helper_functions/index.html" class = "Nav__item__link" > < i class = "Nav__arrow" > < / i > Helper functions< / a > < ul class = 'Nav' > < / ul > < / li > < li class = 'Nav__item has-children' > < a href = "../Cache_API/index.html" class = "Nav__item__link" > < i class = "Nav__arrow" > < / i > Cache API< / a > < ul class = 'Nav' > < li class = 'Nav__item ' > < a href = "../Cache_API/How_to_create_a_new_cache.html" > How to create a new cache< / a > < / li > < li class = 'Nav__item ' > < a href = "../Cache_API/CacheInterface.html" > CacheInterface< / a > < / li > < / ul > < / li > < li class = 'Nav__item ' > < a href = "../Technical_recommendations/index.html" class = "Nav__item__link" > < i class = "Nav__arrow" > < / i > Technical recommendations< / a > < ul class = 'Nav' > < / ul > < / li > < li class = 'Nav__item has-children' > < a href = "../Bridge_Specific/ActivityPub_(Mastodon).html" class = "Nav__item__link" > < i class = "Nav__arrow" > < / i > Bridge Specific< / a > < ul class = 'Nav' > < li class = 'Nav__item ' > < a href = "../Bridge_Specif
2022-03-22 20:34:02 +00:00
< div class = "Links" >
< hr / >
< a href = "https://github.com/RSS-Bridge/rss-bridge" target = "_blank" rel = "noopener noreferrer" > GitHub Repository< / a >
< br / >
< a href = "https://github.com/RSS-Bridge/rss-bridge/issues" target = "_blank" rel = "noopener noreferrer" > Help/Support/Bugs< / a >
< br / >
< a href = "https://github.com/RSS-Bridge/rss-bridge/pkgs/container/rss-bridge" target = "_blank" rel = "noopener noreferrer" > Docker Images< / a >
< br / >
< / div >
< div class = "CodeToggler" >
< hr / >
< label class = "Checkbox" > Show Code Blocks < input type = "checkbox" class = "CodeToggler__button--main" checked = "checked" / >
< div class = "Checkbox__indicator" > < / div >
< / label >
< / div >
2022-10-06 20:13:30 +00:00
< div class = "DarkModeToggler" >
< hr / >
< label class = "Checkbox" > Dark Mode < input type = "checkbox" class = "ColorMode__button" / >
< div class = "Checkbox__indicator" > < / div >
< / label >
< / div >
2022-03-22 20:34:02 +00:00
< div class = "PoweredBy" >
< hr / >
Powered by Daux.io < / div >
< / div >
< / aside >
< div class = "Columns__right" >
< div class = "Columns__right__content" >
< div class = "doc_content" >
< article class = "Page" >
< div class = "Page__header" >
< h1 > < a href = "../Helper_functions/index.html" > Helper functions< / a > < / h1 >
< span class = "ModifiedDate" >
2025-03-24 20:12:57 +00:00
March 24, 2025 at 1:12 PM < / span >
2022-03-22 20:34:02 +00:00
< span class = "EditOn" >
< a href = "https://github.com/RSS-Bridge/rss-bridge/tree/master/docs/06_Helper_functions/index.md" target = "_blank" >
Edit on GitHub < / a >
< / span >
< / div >
< div class = "s-content" >
< h1 > < a id = "getinput" href = "#getinput" class = "Permalink" aria-hidden = "true" title = "Permalink" > #< / a > getInput< / h1 >
< p > The < code > getInput< / code > function is used to receive a value for a parameter, specified in < code > const PARAMETERS< / code > < / p >
< pre > < code class = "language-PHP" > $this-> getInput('your input name here');
< / code > < / pre >
2023-09-10 19:50:39 +00:00
< p > < code > getInput< / code > will either return the value for your parameter
or < code > null< / code > if the parameter is unknown or not specified.< / p >
2024-04-04 17:29:24 +00:00
< p > < a href = "https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/BridgeAbstract.php" class = "Link--external" rel = "noopener noreferrer" > Defined in lib/BridgeAbstract.php< / a > < / p >
2023-03-06 19:02:19 +00:00
< h1 > < a id = "getkey" href = "#getkey" class = "Permalink" aria-hidden = "true" title = "Permalink" > #< / a > getKey< / h1 >
2023-09-10 19:50:39 +00:00
< p > The < code > getKey< / code > function is used to receive the key name to a selected list
value given the name of the list, specified in < code > const PARAMETERS< / code >
2023-03-06 19:02:19 +00:00
Is able to work with multidimensional list arrays.< / p >
< pre > < code class = "language-PHP" > // Given a multidimensional array like this
const PARAMETERS = [[
'country' => [
'name' => 'Country',
'type' => 'list',
'values' => [
'North America' => [
'Mexico' => 'mx',
'United States' => 'us'
],
'South America' => [
'Uruguay' => 'uy',
'Venezuela' => 've'
],
]
]
]],
// Provide the list name to the function
$this-> getKey('country');
// if the selected value was " ve" , this function will return " Venezuela"
< / code > < / pre >
2023-09-10 19:50:39 +00:00
< p > < code > getKey< / code > will either return the key name for your parameter or < code > null< / code > if the parameter
is unknown or not specified.< / p >
2024-04-04 17:29:24 +00:00
< p > < a href = "https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/BridgeAbstract.php" class = "Link--external" rel = "noopener noreferrer" > Defined in lib/BridgeAbstract.php< / a > < / p >
2022-03-22 20:34:02 +00:00
< h1 > < a id = "getcontents" href = "#getcontents" class = "Permalink" aria-hidden = "true" title = "Permalink" > #< / a > getContents< / h1 >
< p > The < code > getContents< / code > function uses < a href = "https://secure.php.net/manual/en/book.curl.php" class = "Link--external" rel = "noopener noreferrer" > cURL< / a > to acquire data from the specified URI while respecting the various settings defined at a global level by RSS-Bridge (i.e., proxy host, user agent, etc.). This function accepts a few parameters:< / p >
< table >
< thead >
< tr >
< th > Parameter< / th >
< th > Type< / th >
< th > Optional< / th >
< th > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td > < code > url< / code > < / td >
< td > string< / td >
< td > < em > required< / em > < / td >
< td > The URL of the contents to acquire< / td >
< / tr >
< tr >
< td > < code > header< / code > < / td >
< td > array< / td >
< td > < em > optional< / em > < / td >
< td > An array of HTTP header fields to set, in the format < code > array('Content-type: text/plain', 'Content-length: 100')< / code > , see < a href = "https://secure.php.net/manual/en/function.curl-setopt.php" class = "Link--external" rel = "noopener noreferrer" > CURLOPT_HTTPHEADER< / a > < / td >
< / tr >
< tr >
< td > < code > opts< / code > < / td >
< td > array< / td >
< td > < em > optional< / em > < / td >
< td > An array of cURL options in the format < code > array(CURLOPT_POST => 1);< / code > , see < a href = "https://secure.php.net/manual/en/function.curl-setopt.php" class = "Link--external" rel = "noopener noreferrer" > curl_setopt< / a > for a complete list of options.< / td >
< / tr >
2022-10-29 01:31:11 +00:00
< tr >
< td > < code > returnFull< / code > < / td >
< td > boolean< / td >
< td > < em > optional< / em > < / td >
< td > Specifies whether to return the response body from cURL (default) or the response body, code, headers, etc.< / td >
< / tr >
2022-03-22 20:34:02 +00:00
< / tbody >
< / table >
< pre > < code class = "language-PHP" > $header = array('Content-type:text/plain', 'Content-length: 100');
$opts = array(CURLOPT_POST => 1);
$html = getContents($url, $header, $opts);
< / code > < / pre >
2024-04-04 17:29:24 +00:00
< p > < a href = "https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/contents.php" class = "Link--external" rel = "noopener noreferrer" > Defined in lib/contents.php< / a > < / p >
2022-03-22 20:34:02 +00:00
< h1 > < a id = "getsimplehtmldom" href = "#getsimplehtmldom" class = "Permalink" aria-hidden = "true" title = "Permalink" > #< / a > getSimpleHTMLDOM< / h1 >
2023-09-10 19:50:39 +00:00
< p > The < code > getSimpleHTMLDOM< / code > function is a wrapper for the
< a href = "https://simplehtmldom.sourceforge.io/" class = "Link--external" rel = "noopener noreferrer" > simple_html_dom< / a > < a href = "https://simplehtmldom.sourceforge.io/docs/1.9/api/file_get_html/" class = "Link--external" rel = "noopener noreferrer" > file_get_html< / a > function in order to provide context by design.< / p >
2022-03-22 20:34:02 +00:00
< pre > < code class = "language-PHP" > $html = getSimpleHTMLDOM('your URI');
< / code > < / pre >
2024-04-04 17:29:24 +00:00
< p > < a href = "https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/contents.php" class = "Link--external" rel = "noopener noreferrer" > Defined in lib/contents.php< / a > < / p >
2022-03-22 20:34:02 +00:00
< h1 > < a id = "getsimplehtmldomcached" href = "#getsimplehtmldomcached" class = "Permalink" aria-hidden = "true" title = "Permalink" > #< / a > getSimpleHTMLDOMCached< / h1 >
2023-09-10 19:50:39 +00:00
< p > The < code > getSimpleHTMLDOMCached< / code > function does the same as the
< a href = "#getsimplehtmldom" > < code > getSimpleHTMLDOM< / code > < / a > function,
except that the content received for the given URI is stored in a cache
and loaded from cache on the next request if the specified cache duration
was not reached.< / p >
< p > Use this function for data that is very unlikely to change between consecutive requests to < strong > RSS-Bridge< / strong > .
This function allows to specify the cache duration with the second parameter.< / p >
2022-03-22 20:34:02 +00:00
< pre > < code class = "language-PHP" > $html = getSimpleHTMLDOMCached('your URI', 86400); // Duration 24h
< / code > < / pre >
2024-04-04 17:29:24 +00:00
< p > < a href = "https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/contents.php" class = "Link--external" rel = "noopener noreferrer" > Defined in lib/contents.php< / a > < / p >
2022-03-22 20:34:02 +00:00
< h1 > < a id = "returnclienterror" href = "#returnclienterror" class = "Permalink" aria-hidden = "true" title = "Permalink" > #< / a > returnClientError< / h1 >
2023-09-10 19:50:39 +00:00
< p > The < code > returnClientError< / code > function aborts execution of the current bridge
and returns the given error message with error code < strong > 400< / strong > :< / p >
2022-03-22 20:34:02 +00:00
< pre > < code class = "language-PHP" > returnClientError('Your error message')
< / code > < / pre >
< p > Use this function when the user provided invalid parameter or a required parameter is missing.< / p >
2024-04-04 17:29:24 +00:00
< p > < a href = "https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/utils.php" class = "Link--external" rel = "noopener noreferrer" > Defined in lib/utils.php< / a > < / p >
2022-03-22 20:34:02 +00:00
< h1 > < a id = "returnservererror" href = "#returnservererror" class = "Permalink" aria-hidden = "true" title = "Permalink" > #< / a > returnServerError< / h1 >
< p > The < code > returnServerError< / code > function aborts execution of the current bridge and returns the given error message with error code < strong > 500< / strong > :< / p >
< pre > < code class = "language-PHP" > returnServerError('Your error message')
< / code > < / pre >
2023-09-10 19:50:39 +00:00
< p > Use this function when a problem occurs that has nothing to do with the parameters provided by the user.
(like: Host service gone missing, empty data received, etc…)< / p >
2024-04-04 17:29:24 +00:00
< p > < a href = "https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/utils.php" class = "Link--external" rel = "noopener noreferrer" > Defined in lib/utils.php< / a > < / p >
2022-03-22 20:34:02 +00:00
< h1 > < a id = "defaultlinkto" href = "#defaultlinkto" class = "Permalink" aria-hidden = "true" title = "Permalink" > #< / a > defaultLinkTo< / h1 >
2023-09-10 19:50:39 +00:00
< p > Automatically replaces any relative URL in a given string or DOM object
(i.e. the one returned by < a href = "#getsimplehtmldom" > getSimpleHTMLDOM< / a > ) with an absolute URL.< / p >
2022-03-22 20:34:02 +00:00
< pre > < code class = "hljs php" > defaultLinkTo ( mixed $content, string $server ) : object
< / code > < / pre >
< p > Returns a DOM object (even if provided a string).< / p >
< p > < strong > Remarks< / strong > < / p >
< ul >
< li > Only handles < code > < a> < / code > and < code > < img> < / code > tags.< / li >
< / ul >
< p > < strong > Example< / strong > < / p >
< pre > < code class = "hljs php" > $html = < span class = "hljs-string" > '< img src="/blob/master/README.md"> '< / span > ;
$html = defaultLinkTo($html, < span class = "hljs-string" > 'https://www.github.com/rss-bridge/rss-bridge'< / span > ); < span class = "hljs-comment" > // Using custom server< / span >
$html = defaultLinkTo($html, < span class = "hljs-keyword" > $this< / span > -> getURI()); < span class = "hljs-comment" > // Using bridge URL< / span >
< span class = "hljs-comment" > // Output< / span >
< span class = "hljs-comment" > // < img src="https://www.github.com/rss-bridge/rss-bridge/blob/master/README.md"> < / span >
2022-05-10 07:38:16 +00:00
< / code > < / pre >
2024-04-04 17:29:24 +00:00
< p > < a href = "https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/html.php" class = "Link--external" rel = "noopener noreferrer" > Defined in lib/html.php< / a > < / p >
2022-05-10 07:38:16 +00:00
< h1 > < a id = "backgroundtoimg" href = "#backgroundtoimg" class = "Permalink" aria-hidden = "true" title = "Permalink" > #< / a > backgroundToImg< / h1 >
< p > Replaces tags with styles of < code > backgroud-image< / code > by < code > < img /> < / code > tags.< / p >
< pre > < code class = "hljs php" > backgroundToImg(mixed $htmlContent) : object
< / code > < / pre >
< p > Returns a DOM object (even if provided a string).< / p >
2024-04-04 17:29:24 +00:00
< p > < a href = "https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/html.php" class = "Link--external" rel = "noopener noreferrer" > Defined in lib/html.php< / a > < / p >
2022-05-10 07:38:16 +00:00
< h1 > < a id = "extractfromdelimiters" href = "#extractfromdelimiters" class = "Permalink" aria-hidden = "true" title = "Permalink" > #< / a > extractFromDelimiters< / h1 >
< p > Extract the first part of a string matching the specified start and end delimiters.< / p >
< pre > < code class = "hljs php" > < span class = "hljs-function" > < span class = "hljs-keyword" > function< / span > < span class = "hljs-title" > extractFromDelimiters< / span > < span class = "hljs-params" > (string $string, string $start, string $end)< / span > : < span class = "hljs-title" > mixed< / span >
< / span > < / code > < / pre >
< p > Returns the extracted string if delimiters were found and false otherwise.< / p >
< p > < strong > Example< / strong > < / p >
< pre > < code class = "hljs php" > $string = < span class = "hljs-string" > '< div> Post author: John Doe< /div> '< / span > ;
$start = < span class = "hljs-string" > 'author: '< / span > ;
$end = < span class = "hljs-string" > '< '< / span > ;
$extracted = extractFromDelimiters($string, $start, $end);
< span class = "hljs-comment" > // Output< / span >
< span class = "hljs-comment" > // 'John Doe'< / span >
< / code > < / pre >
2024-04-04 17:29:24 +00:00
< p > < a href = "https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/html.php" class = "Link--external" rel = "noopener noreferrer" > Defined in lib/html.php< / a > < / p >
2022-05-10 07:38:16 +00:00
< h1 > < a id = "stripwithdelimiters" href = "#stripwithdelimiters" class = "Permalink" aria-hidden = "true" title = "Permalink" > #< / a > stripWithDelimiters< / h1 >
2022-12-27 23:35:19 +00:00
< p > Remove one or more part(s) of a string using a start and end delimiter.
2022-05-10 07:38:16 +00:00
It is the inverse of < code > extractFromDelimiters< / code > .< / p >
< pre > < code class = "hljs php" > < span class = "hljs-function" > < span class = "hljs-keyword" > function< / span > < span class = "hljs-title" > stripWithDelimiters< / span > < span class = "hljs-params" > (string $string, string $start, string $end)< / span > : < span class = "hljs-title" > string< / span >
< / span > < / code > < / pre >
< p > Returns the cleaned string, even if no delimiters were found.< / p >
< p > < strong > Example< / strong > < / p >
< pre > < code class = "hljs php" > $string = < span class = "hljs-string" > 'foo< script> superscript()< /script> bar'< / span > ;
$start = < span class = "hljs-string" > '< script> '< / span > ;
$end = < span class = "hljs-string" > '< /script> '< / span > ;
$cleaned = stripWithDelimiters($string, $start, $end);
< span class = "hljs-comment" > // Output< / span >
< span class = "hljs-comment" > // 'foobar'< / span >
< / code > < / pre >
2024-04-04 17:29:24 +00:00
< p > < a href = "https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/html.php" class = "Link--external" rel = "noopener noreferrer" > Defined in lib/html.php< / a > < / p >
2022-05-10 07:38:16 +00:00
< h1 > < a id = "striprecursivehtmlsection" href = "#striprecursivehtmlsection" class = "Permalink" aria-hidden = "true" title = "Permalink" > #< / a > stripRecursiveHTMLSection< / h1 >
< p > Remove HTML sections containing one or more sections using the same HTML tag.< / p >
< pre > < code class = "hljs php" > < span class = "hljs-function" > < span class = "hljs-keyword" > function< / span > < span class = "hljs-title" > stripRecursiveHTMLSection< / span > < span class = "hljs-params" > (string $string, string $tag_name, string $tag_start)< / span > : < span class = "hljs-title" > string< / span >
< / span > < / code > < / pre >
< p > < strong > Example< / strong > < / p >
< pre > < code class = "hljs php" > $string = < span class = "hljs-string" > 'foo< div class="ads"> < div> ads< /div> ads< /div> bar'< / span > ;
$tag_name = < span class = "hljs-string" > 'div'< / span > ;
$tag_start = < span class = "hljs-string" > '< div class="ads"> '< / span > ;
$cleaned = stripRecursiveHTMLSection($string, $tag_name, $tag_start);
< span class = "hljs-comment" > // Output< / span >
< span class = "hljs-comment" > // 'foobar'< / span >
< / code > < / pre >
2024-04-04 17:29:24 +00:00
< p > < a href = "https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/html.php" class = "Link--external" rel = "noopener noreferrer" > Defined in lib/html.php< / a > < / p >
2022-05-10 07:38:16 +00:00
< h1 > < a id = "markdowntohtml" href = "#markdowntohtml" class = "Permalink" aria-hidden = "true" title = "Permalink" > #< / a > markdownToHtml< / h1 >
< p > Converts markdown input to HTML using < a href = "https://parsedown.org/" class = "Link--external" rel = "noopener noreferrer" > Parsedown< / a > .< / p >
2023-05-11 19:24:43 +00:00
< table >
< thead >
< tr >
< th > Parameter< / th >
< th > Type< / th >
< th > Optional< / th >
< th > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td > < code > string< / code > < / td >
< td > string< / td >
< td > < em > required< / em > < / td >
< td > The URL of the contents to acquire< / td >
< / tr >
< tr >
< td > < code > config< / code > < / td >
< td > array< / td >
< td > < em > optional< / em > < / td >
< td > An array of Parsedown options in the format < code > ['breaksEnabled' => true]< / code > < / td >
< / tr >
< / tbody >
< / table >
< p > Valid options:< / p >
< table >
< thead >
< tr >
< th > Option< / th >
< th > Default< / th >
< th > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td > < code > breaksEnabled< / code > < / td >
< td > < code > false< / code > < / td >
< td > Enable automatic line breaks< / td >
< / tr >
< tr >
< td > < code > markupEscaped< / code > < / td >
< td > < code > false< / code > < / td >
< td > Escape inline markup (HTML)< / td >
< / tr >
< tr >
< td > < code > urlsLinked< / code > < / td >
< td > < code > true< / code > < / td >
< td > Automatically convert URLs to links< / td >
< / tr >
< / tbody >
< / table >
< pre > < code class = "hljs php" > < span class = "hljs-function" > < span class = "hljs-keyword" > function< / span > < span class = "hljs-title" > markdownToHtml< / span > < span class = "hljs-params" > (string $string, array $config = [])< / span > : < span class = "hljs-title" > string< / span >
2022-05-10 07:38:16 +00:00
< / span > < / code > < / pre >
< p > < strong > Example< / strong > < / p >
< pre > < code class = "hljs php" > $input = < span class = "hljs-string" > < < < EOD
RELEASE-2.8
* Share QR code of a token
* Dark mode improvemnet
* Fix some layout issues
* Add shortcut to launch the app with screenshot mode on
* Translation improvements
EOD;< / span >
$html = markdownToHtml($input);
< span class = "hljs-comment" > // Output:< / span >
< span class = "hljs-comment" > // < p> RELEASE-2.8< /p> < / span >
< span class = "hljs-comment" > // < ul> < / span >
< span class = "hljs-comment" > // < li> Share QR code of a token< /li> < / span >
< span class = "hljs-comment" > // < li> Dark mode improvemnet< /li> < / span >
< span class = "hljs-comment" > // < li> Fix some layout issues< /li> < / span >
< span class = "hljs-comment" > // < li> Add shortcut to launch the app with screenshot mode on< /li> < / span >
< span class = "hljs-comment" > // < li> Translation improvements< /li> < / span >
< span class = "hljs-comment" > // < /ul> < / span >
2022-03-22 20:34:02 +00:00
< / code > < / pre >
2024-04-04 17:29:24 +00:00
< p > < a href = "https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/html.php" class = "Link--external" rel = "noopener noreferrer" > Defined in lib/html.php< / a > < / p >
< h1 > < a id = "e" href = "#e" class = "Permalink" aria-hidden = "true" title = "Permalink" > #< / a > e< / h1 >
< p > The < code > e< / code > function is used to convert special characters to HTML entities< / p >
< pre > < code class = "language-PHP" > e('0 < 1 and 2 > 1');
< / code > < / pre >
< p > < code > e< / code > will return the content of the string escape that can be rendered as is in HTML< / p >
< p > < a href = "https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/html.php" class = "Link--external" rel = "noopener noreferrer" > Defined in lib/html.php< / a > < / p >
< h1 > < a id = "truncate" href = "#truncate" class = "Permalink" aria-hidden = "true" title = "Permalink" > #< / a > truncate< / h1 >
< p > The < code > truncate< / code > function is used to shorten a string if exceeds a certain length, and add a string indicating that the string has been shortened.< / p >
< pre > < code class = "language-PHP" > truncate('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed a neque nunc. Nam nibh sem.', 20 , '...');
< / code > < / pre >
< p > < a href = "https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/html.php" class = "Link--external" rel = "noopener noreferrer" > Defined in lib/html.php< / a > < / p >
< h1 > < a id = "sanitize" href = "#sanitize" class = "Permalink" aria-hidden = "true" title = "Permalink" > #< / a > sanitize< / h1 >
< p > The < code > sanitize< / code > function is used to remove some tags from a given HTML text.< / p >
< pre > < code class = "language-PHP" > $html = '< head> < title> Sample Page< /title> < /head>
< body> < p> Lorem ipsum dolor sit amet, consectetur adipiscing elit...< /p>
< iframe src=" https://www.example.com" width=" 600" height=" 400" frameborder=" 0" allowfullscreen> < /iframe>
< /body>
< /html> ';
$tags_to_remove = ['script', 'iframe', 'input', 'form'];
$attributes_to_keep = ['title', 'href', 'src'];
$text_to_keep = [];
sanitize($html, $tags_to_remove, $attributes_to_keep, $text_to_keep);
< / code > < / pre >
< p > This function returns a simplehtmldom object of the remaining contents.< / p >
< p > < a href = "https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/html.php" class = "Link--external" rel = "noopener noreferrer" > Defined in lib/html.php< / a > < / p >
< h1 > < a id = "convertlazyloading" href = "#convertlazyloading" class = "Permalink" aria-hidden = "true" title = "Permalink" > #< / a > convertLazyLoading< / h1 >
< p > The < code > convertLazyLoading< / code > function is used to convert onvert lazy-loading images and frames (video embeds) into static elements. It accepts the HTML content as HTML objects or string objects. It returns the HTML content with fixed image/frame URLs (same type as input).< / p >
< pre > < code class = "language-PHP" > $html = '< html>
< body style=" background-image: url('bgimage.jpg');" >
< h1> Hello world!< /h1>
< /body>
< /html>
backgroundToImg($html);
< / code > < / pre >
< p > < a href = "https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/html.php" class = "Link--external" rel = "noopener noreferrer" > Defined in lib/html.php< / a > < / p >
< h1 > < a id = "json-encode" href = "#json-encode" class = "Permalink" aria-hidden = "true" title = "Permalink" > #< / a > Json::encode< / h1 >
< p > The < code > Json::encode< / code > function is used to encode a value as à JSON string.< / p >
< pre > < code class = "language-PHP" > $array = [
" foo" => " bar" ,
" bar" => " foo" ,
];
Json::encode($array, true, true);
< / code > < / pre >
< p > < a href = "https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/utils.php" class = "Link--external" rel = "noopener noreferrer" > Defined in lib/utils.php< / a > < / p >
< h1 > < a id = "json-decode" href = "#json-decode" class = "Permalink" aria-hidden = "true" title = "Permalink" > #< / a > Json::decode< / h1 >
< p > The < code > Json::decode< / code > function is used to decode a JSON string into à PHP variable.< / p >
< pre > < code class = "language-PHP" > $json = '{
" foo" : " bar" ,
" bar" : " foo"
}';
Json::decode($json);
< / code > < / pre >
< p > < a href = "https://github.com/RSS-Bridge/rss-bridge/blob/master/lib/utils.php" class = "Link--external" rel = "noopener noreferrer" > Defined in lib/utils.php< / a > < / p >
2022-03-22 20:34:02 +00:00
< / div >
< nav >
< ul class = "Pager" >
< li class = Pager--prev > < a href = "../Bridge_API/XPathAbstract.html" > Previous< / a > < / li > < li class = Pager--next > < a href = "../Cache_API/index.html" > Next< / a > < / li > < / ul >
< / nav >
< / article >
< / div >
< / div >
< / div >
< / div >
<!-- JS -->
< script src = "../themes/daux/js/daux.min.js" > < / script >
< script >
window.searchLanguage = "";
window.searchTranslation = {"Search_one_result":"1 result","Search_results":"!count results","Search_no_results":"Nothing found","Search_common_words_ignored":"Common words are largely ignored","Search_too_short":"Search too short","Search_one_character_or_more":"Should be one character or more","Search_should_be_x_or_more":"Should be !min characters or more","Link_previous":"Previous","Link_next":"Next"};
< / script >
<!-- Search -->
< script type = "text/javascript" src = "../daux_libraries/search.min.js" > < / script >
< script >
window.search({'base_url': '../'})
< / script >
< / body >
< / html >