Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $app = new TestApplication;
- $app->run();
- class TestApplication
- {
- public function run()
- {
- $post = new Post("Tutorial membuat CRUD dengan Laravel: [youtube id=HmV4gXIkP6k]");
- echo $post->getHtmlContent();
- $post = new Post("Tutorial membuat CRUD dengan Laravel: [youtube id=HmV4gXIkP6k]" .
- "Contoh kode bisa dilihat di bawah ini: [gist id=9fdb82372bd10b5627e0]");
- echo $post->getHtmlContent();
- }
- }
- class Post
- {
- protected $content;
- public function __construct($content)
- {
- $this->content = $content;
- $methods = get_class_methods($this);
- foreach ($methods as $method) {
- if ($method == '__construct' || $method == 'getHtmlContent') {
- continue;
- }
- $this->{$method}();
- }
- }
- public function getHtmlContent()
- {
- return $this->content;// YOUR CODE HERE
- }
- public function shortYoutube()
- {
- if (strpos($this->content, '[youtube id=')) {
- return str_replace('number link', 'embeded link', $this->content);
- }
- }
- public function shortGist()
- {
- if (strpos($this->content, 'gist id=')) {
- return str_replace('number link', 'embeded link', $this->content);
- }
- }
- // JUST WRITE OTHER FUNCTION IF NEED TO TRANSLATE NEW SHORTTAG
- }
- // OR HERE, IF YOU REALLY NEED TO WRITE ANOTHER FUNCTION OR CLASS OR INTERFACE OR TRAIT
Add Comment
Please, Sign In to add comment