You are here

protected function SendGridMail::getSubString in SendGrid Integration 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Mail/SendGridMail.php \Drupal\sendgrid_integration\Plugin\Mail\SendGridMail::getSubString()

Returns a string that is contained within another string.

Returns the string from within $source that is some where after $target and is between $beginning_character and $ending_character.

Swiped from SMTP module. Thanks!

Parameters

string $source: A string containing the text to look through.

string $target: A string containing the text in $source to start looking from.

string $beginning_character: A string containing the character just before the sought after text.

string $ending_character: A string containing the character just after the sought after text.

Return value

string A string with the text found between the $beginning_character and the $ending_character.

1 call to SendGridMail::getSubString()
SendGridMail::mail in src/Plugin/Mail/SendGridMail.php
Sends a message composed by \Drupal\Core\Mail\MailManagerInterface->mail().

File

src/Plugin/Mail/SendGridMail.php, line 553
Implements Drupal MailSystemInterface.

Class

SendGridMail
@file Implements Drupal MailSystemInterface.

Namespace

Drupal\sendgrid_integration\Plugin\Mail

Code

protected function getSubString($source, $target, $beginning_character, $ending_character) {
  $search_start = strpos($source, $target) + 1;
  $first_character = strpos($source, $beginning_character, $search_start) + 1;
  $second_character = strpos($source, $ending_character, $first_character) + 1;
  $substring = mb_substr($source, $first_character, $second_character - $first_character);
  $string_length = mb_strlen($substring) - 1;
  if ($substring[$string_length] == $ending_character) {
    $substring = mb_substr($substring, 0, $string_length);
  }
  return $substring;
}