Jump to content

MoFish

Members
  • Posts

    227
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

MoFish's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

  1. @ginerjm I think that's the problem; I'm trying to treat them all the same when they probably should be a little more unique. They slightly vary which is throwing me. {% snippet 'hello' %} to be <x-snippet name="hello" /> with a self closing tag {% extend 'boom' %} to be <x-template name="boom"> without a self closing tag {% endextend %} with the self closing tag </x-template>
  2. @BarandI tried that, It look's like laravel components which im using to render them out; need the trailing /> in order to work correctly 😠 Can some regex magic be done in this scenario or is str_replace the way forward? Thanks so much for your help.
  3. @Barand Sorry to bother you. Everything was going great until I came across the last couple tags I needed to replace which were not self closing like the others (example 4 and example 5 below) which caused issues. Can you think of a way around this problem? Or is there some regex solution which can pick out the first and last parts whilst skipping the word in the quotes? 🤢 {% snippet name="hello1" %} // OK <x-snippet name="hello1" /> {% setting name="hello2" %} // OK <x-setting name="hello2" /> {% collection name="hello3" %} // OK <x-collection name="hello3" /> {% extend "boom" %} // Issue with /> <x-template name="boom"> {% endextend %} // Issue with /> <x-template> Code $source = "{% snippet name='hello1' %} {% setting name='hello2' %} {% collection name='hello3' %} {% extend 'boom' %} {% endextend %}"; $html = str_replace([ '{% snippet ', '{% collection ', '{% setting ', '{% extend ', '{% endextend ', '%}' ], [ '<x-snippet name=', '<x-collection name=', '<x-setting name=', '<x-template name=', '</x-template ', '/>' ], $source); dump($html); Result (see areas in red which are incorrect tags)
  4. @BarandThank you very much; that is exactly what I was looking for and works perfectly. Quick question: Is there a more elegant way to do multiple replacements? The below code does work; but looks a little unwealdy. $html = str_replace( ['{% snippet ', '%}'], ['<x-snippet name=', '/>'], $page->template->source); $html = str_replace( ['{% collection ', '%}'], ['<x-collection name=', '/>'], $html); $html = str_replace( ['{% setting ', '%}'], ['<x-setting name=', '/>'], $html);
  5. $success = preg_match_all("/{% snippet '(.*?)' %}/i", $html, $results); if ($success) { print_r($results); } Not very far; i got as far as finding the lines of code in the html.
  6. Hi, I have some html stored in a variable called $html Inside this $html variable I have the following content {% snippet "footer" %} I would like to find all instances of this tag in the $html and replace it with <x-snip name="footer" /> Could anyone advise me on how this would be best achieved? Thank you, MoFish -- Ideally this would work for any number of these custom tags e.g. {% snippet "footer" %} and {% snippet "header" %} would become <x-snip name="footer" /> and <x-snip name="header" />
  7. Hi, I have a textarea called registerDomain which i enter multiple domain names into (separated by a new line) e.g. www.google.com www.sky.com www.bt.com I have the following code to get each of the domains and format them like google.com (lowercase without any spaces) sky.com (lowercase without any spaces) bt.com (lowercase without any spaces) The below code I have works perfectly, however its awful to look at. I wondered if anyone could advise on a cleaner/more elegant way of achieving this. Thanks, if (isset($_POST['submit'])) { $values = trim($_POST['registerDomain']); $array = explode("\n", $values); $array = array_filter($array, 'trim'); foreach ($array as $line) { $domain = addslashes($line); $domain = preg_replace("/\r|\n/", "", $domain); $domain = strtolower($domain); $domain = str_replace("www.", "", $domain); $domain = str_replace(" ", "", $domain);
  8. @NotionCommotion Thank you for all your help, i fixed the issue. It was the \r as you suggested which was causing the issue.
  9. @NotionCommotion You are correct, some nulls are coming back but i don't understand why there would be no response message with them. $textAr: ["www.google.com\r","www.bbc.com\r","www.sky.com"] $line: google.com bool(false) $line: bbc.com bool(false) $line: sky.com string(203) " status error error Domain sky.com already registered " array(3) { ["www.google.com "]=> bool(false) ["www.bbc.com "]=> bool(false) ["www.sky.com"]=> string(203) " status error error Domain sky.com already registered " }
  10. @NotionCommotion I was hoping for something like this, as each of these are already registered. However, only get the last response
  11. $textAr: ["www.google.com\r","www.yahoo.com"] $line: www.google.com $line: www.yahoo.com status error error Domain yahoo.com already registered Array ( [0] => [1] => status error error Domain yahoo.com already registered ) Its like the second request blanks out the first. If i do three requests, i only ever get the last one. $textAr: ["www.google.com\r","www.yahoo.com\r","www.bbc.com"] $line: www.google.com $line: www.yahoo.com $line: www.bbc.com status error error Domain bbc.com already registered Array ( [0] => [1] => [2] => status error error Domain bbc.com already registered )
  12. @NotionCommotion $line: www.xxx2.com $textAr: ["www.xxx1.com\r","www.xxx2.com"] Array ( [0] => [1] => status error error The domain xxx2.com already exists in our database. This may occur if there is a pending Order for xxx2.com in our database under your account or any other account. You may search for this domain within your control panel.) $result = array(); foreach ($textAr as $line) { $url = "https://example.com/api/domains/blah.xml?domain-name={$line}"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt($ch, CURLOPT_ENCODING, "gzip,deflate"); $result[] = curl_exec ($ch); curl_close ($ch); } printf('$line: %s'.PHP_EOL, $line); printf('$textAr: %s'.PHP_EOL, json_encode($textAr)); print_r($result);
  13. xxx1.com xxx2.com Array ( [0] => [1] => status error error The domain xxx2.com already exists in our database. This may occur if there is a pending Order for xxx2.com in our database under your account or any other account.) As you can see, its only getting the result from the last one for some reason.
  14. Hi @requinix Apologies i removed that URL bit to simplify it. The $line is passed into the url of the curl call so each is unique. When using the below code and calling 3 curl requests for example; it only gets the last string response even if i try to append. I cannot figure out whats going on! if (isset($_POST['submit'])) { $result = array(); foreach ($textAr as $line) { $url = "https://xxx.com/api/domains/meh.xml?auth-userid=xxx&domain-name={$line}"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt($ch, CURLOPT_ENCODING, "gzip,deflate"); $result = curl_exec ($ch); // $result[] = curl_exec ($ch); curl_close ($ch); print_r($result); } // print_r($result); }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.