Enforce Minimum Length by adding spaces So currently I am using the maxlength module (https://drupal.org/project/maxlength) in order to enforce the fields maximum length and I have a view set up that is embedded to a php Rules action (Execute custom PHP code).

Basically if a field is smaller than the maxlength defined, I am looking for a way to output the value with spaces.

For example: Maxlength 5. Field Value: xxx. Output: "xxx&nbsp;&nbsp;" (without quotes)

I can't seem to find the right module/php code to do this.

I think I have 3 directions I can go with this.


I have it save the spaces to the field based on the maxlength specified when saving the field. I don't like this option much since it actually adds spaces to the value in the database.
I somehow edit the view to display the spaces based on the maxlength of the field.
I edit the Rules views_embed_view php output.


Any help would be extremely helpful. Thank you.

Edit: I am using Drupal 7 by the way.
In template file for your field you can use good old PHP sprintf:

$right = sprintf("[%10s]\n",    $s); // right-justification with spaces
$left  = sprintf("[%-10s]\n",   $s); // left-justification with spaces

$right === "    monkey";
$left  === "monkey    ";


In your case
    &lt;?php print $output; ?&gt;

should turn into:

 &lt;?php printf("[%10s]", $output); /* if you want spaces before string */?&gt;