HEX
Server: LiteSpeed
System: Linux premium221.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64
User: madepabj (2566)
PHP: 8.3.26
Disabled: NONE
Upload Files
File: /home/madepabj/www/wp-content/plugins/rehub-framework/vendor/vafpress/classes/util/text.php
<?php

class VP_Util_Text
{

	public static function parse_md($text)
	{
		if(!class_exists('Parsedown'))
		{
			$path = VP_FileSystem::instance()->resolve_path('includes', 'parsedown');
			require $path;
		}
		return Parsedown::instance()->parse($text);
	}

	public static function make_opt($optArray)
	{
		$optString = "";
		foreach ($optArray as $key => $value)
		{
			$optString .= "(" . $key . ":" . $value . ")";
		}
		return $optString;
	}

	public static function print_if_exists($value, $format)
	{
		if (!empty($value))
		{
			if (is_array($value))
			{
				$value = implode($value, ', ');
			}
			call_user_func('printf', $format, $value);
		}	
	}

	public static function return_if_exists($value, $format)
	{
		$result = '';
		if (!empty($value))
		{
			if (is_array($value))
			{
				$value = implode($value, ', ');
			}
			$result = call_user_func('sprintf', $format, $value);
		}
		return $result;
	}

	public static function out($string, $default)
	{
		if( empty($string) )
			echo ''.$default;
		else
			echo ''.$string;
	}

	public static function prefix(&$item, $key, $prefix)
	{
		$item = $prefix . $item;
	}

	public static function prefix_array($array, $prefix)
	{
		array_walk( $array, 'VP_Util_Text::prefix', $prefix);
		return $array;
	}

	public static function starts_with($haystack, $needle)
	{
		return !strncmp($haystack, $needle, strlen($needle));
	}

	public static function ends_with($haystack, $needle)
	{
		$length = strlen($needle);
		if ($length == 0)
		{
			return true;
		}
		return (substr($haystack, -$length) === $needle);
	}

	public static function flanked_by($haystack, $left, $right = '')
	{
		if( $right == '' )
			$right = $left;
		return (self::starts_with($haystack, $left) and self::ends_with($haystack, $right));
	}

}