How to get a string inside of data-cfemail tag by php regular expression?

July 13, 2018, at 08:00 AM

I want to get 344747585151010c745359555d581a575b59 from the string.

[a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="344747585151010c745359555d581a575b59"]

I'm tried the following PHP to capture it:

preg_match_all("/<a [^>]*data-cfemail=\"?([^\">]+)\"?>/", $input_lines, $output_array);
Answer 1

You don't have less than or greater than symbols in your string. Try:



Note, this regex is looser than it could be. I assumed the double quotes encapsulating the data-cfemail were optional, if not this can be simplified.

Answer 2

You can make use of a positive look-behind on the data-cfemail, and then simply match any digit or lowercase letter that comes directly after that:


Breaking this down:

  • (?<=data-cfemail=") - match anything that follows data-cfemail="
  • [\da-z] - match any digit or lowercase letter
  • + - match one or more of the digits / lowercase letters

preg_match("/(?<=data-cfemail=")[\da-z]+/", $input_line, $output_array);


  0 => 344747585151010c745359555d581a575b59

This can be seen working on PHPLiveRegex here.

Rent Charter Buses Company
Composer doesn&#39;t loads files

Composer doesn't loads files

I am facing a problem with php composerAfter adding a dependency on composer

Red Hat JBOSS queue from PHP using AMQP

Red Hat JBOSS queue from PHP using AMQP

I am trying to use PHP AMQP library to connect and consume/subscribe to a Red Hat JBOSS queue systemI have searched for examples or documentation and am unable to find anything JBOSS says is supports AMQP

Send pdf in attachment (Laravel Mail)

Send pdf in attachment (Laravel Mail)

I have this code to get some HTML stored in the column "content" of the "badges" table in a pdf:

HAS_ONE realtion in Yii

HAS_ONE realtion in Yii

I would like to create a junction table that gets taken care of without me manually saving it to the databaseI tried adding this to my relations: